Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame^] | 68 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 78 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 79 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 80 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 81 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 83 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 86 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 89 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 92 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 94 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 95 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 96 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 97 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 98 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 100 | import android.telephony.data.ApnSetting; |
| 101 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 102 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 103 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 104 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 109 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 110 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 117 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 161 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 173 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 175 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 176 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 177 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 178 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 179 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 180 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 181 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 182 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 183 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 184 | import java.io.FileDescriptor; |
| 185 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 187 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 188 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 189 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 190 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 191 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 192 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 193 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 194 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 195 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 196 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Implementation of the ITelephony interface. |
| 200 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 201 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 203 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 204 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 205 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 206 | |
| 207 | // Message codes used with mMainThreadHandler |
| 208 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 209 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 210 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 211 | private static final int CMD_OPEN_CHANNEL = 9; |
| 212 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 213 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 214 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 215 | private static final int CMD_NV_READ_ITEM = 13; |
| 216 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 217 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 218 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 219 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 220 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 221 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 222 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 223 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 224 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 225 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 226 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 227 | private static final int CMD_SEND_ENVELOPE = 25; |
| 228 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 229 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 230 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 231 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 232 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 233 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 234 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 235 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 236 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 237 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 238 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 239 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 240 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 241 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 242 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 243 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 244 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 245 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 246 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 247 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 248 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 249 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 250 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 251 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 252 | private static final int CMD_SWITCH_SLOTS = 50; |
| 253 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 254 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 255 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 256 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 257 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 258 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 259 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 260 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 261 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 262 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 263 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 264 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 265 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 266 | private static final int CMD_MODEM_REBOOT = 64; |
| 267 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 268 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 269 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 270 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 271 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 272 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 273 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 274 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 275 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 276 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 277 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 278 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 279 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 280 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 281 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 282 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 283 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 284 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 285 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 286 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 287 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 288 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 289 | private static final int CMD_GET_CALL_WAITING = 87; |
| 290 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 291 | private static final int CMD_SET_CALL_WAITING = 89; |
| 292 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 293 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 294 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 295 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 296 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 297 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 298 | // Parameters of select command. |
| 299 | private static final int SELECT_COMMAND = 0xA4; |
| 300 | private static final int SELECT_P1 = 0x04; |
| 301 | private static final int SELECT_P2 = 0; |
| 302 | private static final int SELECT_P3 = 0x10; |
| 303 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 304 | /** The singleton instance. */ |
| 305 | private static PhoneInterfaceManager sInstance; |
| 306 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 307 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 308 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 309 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 310 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 311 | private AppOpsManager mAppOps; |
| 312 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 313 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 314 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 315 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 316 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 317 | /** User Activity */ |
| 318 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 319 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 320 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 321 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 322 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 323 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 324 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 325 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 326 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 327 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 328 | // String to store multi SIM allowed |
| 329 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 330 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 331 | // The AID of ISD-R. |
| 332 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 333 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 334 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 335 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 336 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 337 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 338 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 339 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 340 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 341 | */ |
| 342 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 343 | "reset_network_erase_modem_config_enabled"; |
| 344 | |
| 345 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 346 | * A request object to use for transmitting data to an ICC. |
| 347 | */ |
| 348 | private static final class IccAPDUArgument { |
| 349 | public int channel, cla, command, p1, p2, p3; |
| 350 | public String data; |
| 351 | |
| 352 | public IccAPDUArgument(int channel, int cla, int command, |
| 353 | int p1, int p2, int p3, String data) { |
| 354 | this.channel = channel; |
| 355 | this.cla = cla; |
| 356 | this.command = command; |
| 357 | this.p1 = p1; |
| 358 | this.p2 = p2; |
| 359 | this.p3 = p3; |
| 360 | this.data = data; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 365 | * A request object to use for transmitting data to an ICC. |
| 366 | */ |
| 367 | private static final class ManualNetworkSelectionArgument { |
| 368 | public OperatorInfo operatorInfo; |
| 369 | public boolean persistSelection; |
| 370 | |
| 371 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 372 | this.operatorInfo = operatorInfo; |
| 373 | this.persistSelection = persistSelection; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 379 | * request after sending. The main thread will notify the request when it is complete. |
| 380 | */ |
| 381 | private static final class MainThreadRequest { |
| 382 | /** The argument to use for the request */ |
| 383 | public Object argument; |
| 384 | /** The result of the request that is run on the main thread */ |
| 385 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 386 | // The subscriber id that this request applies to. Defaults to |
| 387 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 388 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 389 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 390 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 391 | public Phone phone; |
| 392 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 393 | public WorkSource workSource; |
| 394 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 395 | public MainThreadRequest(Object argument) { |
| 396 | this.argument = argument; |
| 397 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 398 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 399 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 400 | this.argument = argument; |
| 401 | if (phone != null) { |
| 402 | this.phone = phone; |
| 403 | } |
| 404 | this.workSource = workSource; |
| 405 | } |
| 406 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 407 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 408 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 409 | if (subId != null) { |
| 410 | this.subId = subId; |
| 411 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 412 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 413 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 416 | private static final class IncomingThirdPartyCallArgs { |
| 417 | public final ComponentName component; |
| 418 | public final String callId; |
| 419 | public final String callerDisplayName; |
| 420 | |
| 421 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 422 | String callerDisplayName) { |
| 423 | this.component = component; |
| 424 | this.callId = callId; |
| 425 | this.callerDisplayName = callerDisplayName; |
| 426 | } |
| 427 | } |
| 428 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | /** |
| 430 | * A handler that processes messages on the main thread in the phone process. Since many |
| 431 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 432 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 433 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 434 | * on, which will be notified when the operation completes and will contain the result of the |
| 435 | * request. |
| 436 | * |
| 437 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 438 | * note that request.result must be set to something non-null for the calling thread to |
| 439 | * unblock. |
| 440 | */ |
| 441 | private final class MainThreadHandler extends Handler { |
| 442 | @Override |
| 443 | public void handleMessage(Message msg) { |
| 444 | MainThreadRequest request; |
| 445 | Message onCompleted; |
| 446 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 447 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 448 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 449 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | |
| 451 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 452 | case CMD_HANDLE_USSD_REQUEST: { |
| 453 | request = (MainThreadRequest) msg.obj; |
| 454 | final Phone phone = getPhoneFromRequest(request); |
| 455 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 456 | String ussdRequest = ussdObject.first; |
| 457 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 458 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 459 | if (!isUssdApiAllowed(request.subId)) { |
| 460 | // Carrier does not support use of this API, return failure. |
| 461 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 462 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 463 | Bundle returnData = new Bundle(); |
| 464 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 465 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 466 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 467 | request.result = true; |
| 468 | notifyRequester(request); |
| 469 | return; |
| 470 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 471 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 472 | try { |
| 473 | request.result = phone != null |
| 474 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 475 | } catch (CallStateException cse) { |
| 476 | request.result = false; |
| 477 | } |
| 478 | // Wake up the requesting thread |
| 479 | notifyRequester(request); |
| 480 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 483 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 484 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 485 | final Phone phone = getPhoneFromRequest(request); |
| 486 | request.result = phone != null ? |
| 487 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 488 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 489 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 490 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 491 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 492 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 493 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 494 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 495 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 497 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 498 | if (uiccCard == null) { |
| 499 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 500 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 501 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 502 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 503 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 504 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 505 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 506 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 507 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 509 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 | break; |
| 511 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 512 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 513 | ar = (AsyncResult) msg.obj; |
| 514 | request = (MainThreadRequest) ar.userObj; |
| 515 | if (ar.exception == null && ar.result != null) { |
| 516 | request.result = ar.result; |
| 517 | } else { |
| 518 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 519 | if (ar.result == null) { |
| 520 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 521 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 522 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 523 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 524 | } else { |
| 525 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 526 | } |
| 527 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 528 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 529 | break; |
| 530 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 531 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 532 | request = (MainThreadRequest) msg.obj; |
| 533 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 534 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 535 | if (uiccCard == null) { |
| 536 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 537 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 538 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | } else { |
| 540 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 541 | request); |
| 542 | uiccCard.iccTransmitApduBasicChannel( |
| 543 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 544 | iccArgument.p3, iccArgument.data, onCompleted); |
| 545 | } |
| 546 | break; |
| 547 | |
| 548 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 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("iccTransmitApduBasicChannel: Empty response"); |
| 557 | } else if (ar.exception instanceof CommandException) { |
| 558 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 559 | ar.exception); |
| 560 | } else { |
| 561 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 562 | } |
| 563 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 564 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
| 567 | case CMD_EXCHANGE_SIM_IO: |
| 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("iccExchangeSimIO: 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_EXCHANGE_SIM_IO_DONE, |
| 577 | request); |
| 578 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 579 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 580 | iccArgument.data, onCompleted); |
| 581 | } |
| 582 | break; |
| 583 | |
| 584 | case EVENT_EXCHANGE_SIM_IO_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 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | break; |
| 594 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 595 | case CMD_SEND_ENVELOPE: |
| 596 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 597 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 598 | if (uiccCard == null) { |
| 599 | loge("sendEnvelopeWithStatus: No UICC"); |
| 600 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 601 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 602 | } else { |
| 603 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 604 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 605 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | case EVENT_SEND_ENVELOPE_DONE: |
| 609 | ar = (AsyncResult) msg.obj; |
| 610 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 611 | if (ar.exception == null && ar.result != null) { |
| 612 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 613 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 614 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 615 | if (ar.result == null) { |
| 616 | loge("sendEnvelopeWithStatus: Empty response"); |
| 617 | } else if (ar.exception instanceof CommandException) { |
| 618 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 619 | ar.exception); |
| 620 | } else { |
| 621 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 622 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 623 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 624 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 625 | break; |
| 626 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | case CMD_OPEN_CHANNEL: |
| 628 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 629 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 630 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 631 | if (uiccCard == null) { |
| 632 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 633 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 634 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 635 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 636 | } else { |
| 637 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 638 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 639 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 640 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 641 | break; |
| 642 | |
| 643 | case EVENT_OPEN_CHANNEL_DONE: |
| 644 | ar = (AsyncResult) msg.obj; |
| 645 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 648 | int[] result = (int[]) ar.result; |
| 649 | int channelId = result[0]; |
| 650 | byte[] selectResponse = null; |
| 651 | if (result.length > 1) { |
| 652 | selectResponse = new byte[result.length - 1]; |
| 653 | for (int i = 1; i < result.length; ++i) { |
| 654 | selectResponse[i - 1] = (byte) result[i]; |
| 655 | } |
| 656 | } |
| 657 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 658 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | if (ar.result == null) { |
| 661 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 663 | if (ar.exception != null) { |
| 664 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 665 | } |
| 666 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 667 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 668 | if (ar.exception instanceof CommandException) { |
| 669 | CommandException.Error error = |
| 670 | ((CommandException) (ar.exception)).getCommandError(); |
| 671 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 672 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 673 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 674 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 678 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 680 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 681 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | break; |
| 683 | |
| 684 | case CMD_CLOSE_CHANNEL: |
| 685 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 686 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 687 | if (uiccCard == null) { |
| 688 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 689 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 690 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 691 | } else { |
| 692 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 693 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 694 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | break; |
| 696 | |
| 697 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 699 | break; |
| 700 | |
| 701 | case CMD_NV_READ_ITEM: |
| 702 | request = (MainThreadRequest) msg.obj; |
| 703 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 704 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 705 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 706 | break; |
| 707 | |
| 708 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 709 | ar = (AsyncResult) msg.obj; |
| 710 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 711 | if (ar.exception == null && ar.result != null) { |
| 712 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 713 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | request.result = ""; |
| 715 | if (ar.result == null) { |
| 716 | loge("nvReadItem: Empty response"); |
| 717 | } else if (ar.exception instanceof CommandException) { |
| 718 | loge("nvReadItem: CommandException: " + |
| 719 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 720 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 721 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | } |
| 723 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 724 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 725 | break; |
| 726 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 727 | case CMD_NV_WRITE_ITEM: |
| 728 | request = (MainThreadRequest) msg.obj; |
| 729 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 730 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 731 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 732 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case EVENT_NV_WRITE_ITEM_DONE: |
| 736 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 737 | break; |
| 738 | |
| 739 | case CMD_NV_WRITE_CDMA_PRL: |
| 740 | request = (MainThreadRequest) msg.obj; |
| 741 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 742 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 746 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 747 | break; |
| 748 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 749 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 750 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 751 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 752 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | break; |
| 754 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 755 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 756 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 757 | break; |
| 758 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 759 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 760 | request = (MainThreadRequest) msg.obj; |
| 761 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 762 | request); |
| 763 | Phone phone = getPhoneFromRequest(request); |
| 764 | if (phone != null) { |
| 765 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 766 | } else { |
| 767 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 768 | request.result = false; |
| 769 | notifyRequester(request); |
| 770 | } |
| 771 | break; |
| 772 | } |
| 773 | |
| 774 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 775 | ar = (AsyncResult) msg.obj; |
| 776 | request = (MainThreadRequest) ar.userObj; |
| 777 | if (ar.exception == null && ar.result != null) { |
| 778 | request.result = ar.result; |
| 779 | } else { |
| 780 | // request.result must be set to something non-null |
| 781 | // for the calling thread to unblock |
| 782 | if (request.result != null) { |
| 783 | request.result = ar.result; |
| 784 | } else { |
| 785 | request.result = false; |
| 786 | } |
| 787 | if (ar.result == null) { |
| 788 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 789 | } else if (ar.exception instanceof CommandException) { |
| 790 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 791 | + ar.exception); |
| 792 | } else { |
| 793 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 794 | } |
| 795 | } |
| 796 | notifyRequester(request); |
| 797 | break; |
| 798 | |
| 799 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 800 | request = (MainThreadRequest) msg.obj; |
| 801 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 802 | Phone phone = getPhoneFromRequest(request); |
| 803 | if (phone != null) { |
| 804 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 805 | request.workSource); |
| 806 | } else { |
| 807 | loge("enableNrDualConnectivity: No phone object"); |
| 808 | request.result = |
| 809 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 810 | notifyRequester(request); |
| 811 | } |
| 812 | break; |
| 813 | } |
| 814 | |
| 815 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 816 | ar = (AsyncResult) msg.obj; |
| 817 | request = (MainThreadRequest) ar.userObj; |
| 818 | if (ar.exception == null) { |
| 819 | request.result = |
| 820 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 821 | } else { |
| 822 | request.result = |
| 823 | TelephonyManager |
| 824 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 825 | if (ar.exception instanceof CommandException) { |
| 826 | CommandException.Error error = |
| 827 | ((CommandException) (ar.exception)).getCommandError(); |
| 828 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 829 | request.result = |
| 830 | TelephonyManager |
| 831 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 832 | } |
| 833 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 834 | + ar.exception); |
| 835 | } else { |
| 836 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 837 | } |
| 838 | } |
| 839 | notifyRequester(request); |
| 840 | break; |
| 841 | } |
| 842 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 843 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 844 | request = (MainThreadRequest) msg.obj; |
| 845 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 846 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 847 | break; |
| 848 | |
| 849 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 850 | ar = (AsyncResult) msg.obj; |
| 851 | request = (MainThreadRequest) ar.userObj; |
| 852 | if (ar.exception == null && ar.result != null) { |
| 853 | request.result = ar.result; // Integer |
| 854 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 855 | // request.result must be set to something non-null |
| 856 | // for the calling thread to unblock |
| 857 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 858 | if (ar.result == null) { |
| 859 | loge("getPreferredNetworkType: Empty response"); |
| 860 | } else if (ar.exception instanceof CommandException) { |
| 861 | loge("getPreferredNetworkType: CommandException: " + |
| 862 | ar.exception); |
| 863 | } else { |
| 864 | loge("getPreferredNetworkType: Unknown exception"); |
| 865 | } |
| 866 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 867 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 871 | request = (MainThreadRequest) msg.obj; |
| 872 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 873 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 874 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 878 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 879 | break; |
| 880 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 881 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 882 | request = (MainThreadRequest)msg.obj; |
| 883 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 884 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 888 | ar = (AsyncResult)msg.obj; |
| 889 | request = (MainThreadRequest)ar.userObj; |
| 890 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 891 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 892 | break; |
| 893 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 894 | case CMD_SET_VOICEMAIL_NUMBER: |
| 895 | request = (MainThreadRequest) msg.obj; |
| 896 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 897 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 898 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 899 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 900 | break; |
| 901 | |
| 902 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 903 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 904 | break; |
| 905 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 906 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 907 | request = (MainThreadRequest) msg.obj; |
| 908 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 909 | request); |
| 910 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 911 | break; |
| 912 | |
| 913 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 914 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 915 | break; |
| 916 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 917 | case CMD_PERFORM_NETWORK_SCAN: |
| 918 | request = (MainThreadRequest) msg.obj; |
| 919 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 920 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 921 | break; |
| 922 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 923 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 924 | request = (MainThreadRequest) msg.obj; |
| 925 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 926 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 927 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 928 | request.argument; |
| 929 | int callForwardingReason = args.first; |
| 930 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 931 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 932 | } |
| 933 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 934 | ar = (AsyncResult) msg.obj; |
| 935 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 936 | TelephonyManager.CallForwardingInfoCallback callback = |
| 937 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 938 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 939 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 940 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 941 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 942 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 943 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 944 | // any service for voice call. |
| 945 | if ((callForwardInfo.serviceClass |
| 946 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 947 | callForwardingInfo = new CallForwardingInfo(true, |
| 948 | callForwardInfo.reason, |
| 949 | callForwardInfo.number, |
| 950 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 951 | break; |
| 952 | } |
| 953 | } |
| 954 | // Didn't find a call forward info for voice call. |
| 955 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 956 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 957 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 958 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 959 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 960 | } else { |
| 961 | if (ar.result == null) { |
| 962 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 963 | } |
| 964 | if (ar.exception != null) { |
| 965 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 966 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 967 | int errorCode = TelephonyManager |
| 968 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 969 | if (ar.exception instanceof CommandException) { |
| 970 | CommandException.Error error = |
| 971 | ((CommandException) (ar.exception)).getCommandError(); |
| 972 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 973 | errorCode = TelephonyManager |
| 974 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 975 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 976 | errorCode = TelephonyManager |
| 977 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 978 | } |
| 979 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 980 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 981 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 982 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 983 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 984 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 985 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 986 | request = (MainThreadRequest) msg.obj; |
| 987 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 989 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 990 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 991 | request.argument).first; |
| 992 | request.phone.setCallForwardingOption( |
| 993 | callForwardingInfoToSet.isEnabled() |
| 994 | ? CommandsInterface.CF_ACTION_ENABLE |
| 995 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 996 | callForwardingInfoToSet.getReason(), |
| 997 | callForwardingInfoToSet.getNumber(), |
| 998 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 999 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1000 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1001 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1002 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1003 | ar = (AsyncResult) msg.obj; |
| 1004 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1005 | Consumer<Integer> callback = |
| 1006 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1007 | request.argument).second; |
| 1008 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1009 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1010 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1011 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1012 | if (ar.exception instanceof CommandException) { |
| 1013 | CommandException.Error error = |
| 1014 | ((CommandException) (ar.exception)).getCommandError(); |
| 1015 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1016 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1017 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1019 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1020 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | callback.accept(errorCode); |
| 1024 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1025 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1026 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1027 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1028 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1029 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1030 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1031 | request = (MainThreadRequest) msg.obj; |
| 1032 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1033 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1034 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1035 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1036 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1038 | ar = (AsyncResult) msg.obj; |
| 1039 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1041 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1042 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1043 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1044 | // Service Class is a bit mask per 3gpp 27.007. |
| 1045 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1046 | if (callForwardResults.length > 1 |
| 1047 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1049 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1051 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1052 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1054 | } |
| 1055 | } else { |
| 1056 | if (ar.result == null) { |
| 1057 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1058 | } |
| 1059 | if (ar.exception != null) { |
| 1060 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1061 | } |
| 1062 | if (ar.exception instanceof CommandException) { |
| 1063 | CommandException.Error error = |
| 1064 | ((CommandException) (ar.exception)).getCommandError(); |
| 1065 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1066 | callForwardingStatus = |
| 1067 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1068 | } |
| 1069 | } |
| 1070 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1071 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1072 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1073 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1074 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1075 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1076 | request = (MainThreadRequest) msg.obj; |
| 1077 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1078 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1079 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1080 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1082 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1083 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1084 | ar = (AsyncResult) msg.obj; |
| 1085 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1087 | Consumer<Integer> callback = |
| 1088 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1089 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1090 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | if (ar.exception instanceof CommandException) { |
| 1092 | CommandException.Error error = |
| 1093 | ((CommandException) (ar.exception)).getCommandError(); |
| 1094 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1095 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1096 | } else { |
| 1097 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1098 | } |
| 1099 | } else { |
| 1100 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1101 | } |
| 1102 | } else { |
| 1103 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1104 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1105 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1106 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1107 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1108 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1109 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1110 | ar = (AsyncResult) msg.obj; |
| 1111 | request = (MainThreadRequest) ar.userObj; |
| 1112 | CellNetworkScanResult cellScanResult; |
| 1113 | if (ar.exception == null && ar.result != null) { |
| 1114 | cellScanResult = new CellNetworkScanResult( |
| 1115 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1116 | (List<OperatorInfo>) ar.result); |
| 1117 | } else { |
| 1118 | if (ar.result == null) { |
| 1119 | loge("getCellNetworkScanResults: Empty response"); |
| 1120 | } |
| 1121 | if (ar.exception != null) { |
| 1122 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1123 | } |
| 1124 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1125 | if (ar.exception instanceof CommandException) { |
| 1126 | CommandException.Error error = |
| 1127 | ((CommandException) (ar.exception)).getCommandError(); |
| 1128 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1129 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1130 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1131 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1132 | } |
| 1133 | } |
| 1134 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1135 | } |
| 1136 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1137 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1138 | break; |
| 1139 | |
| 1140 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1141 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1142 | ManualNetworkSelectionArgument selArg = |
| 1143 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1144 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1145 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1146 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1147 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1148 | break; |
| 1149 | |
| 1150 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1151 | ar = (AsyncResult) msg.obj; |
| 1152 | request = (MainThreadRequest) ar.userObj; |
| 1153 | if (ar.exception == null) { |
| 1154 | request.result = true; |
| 1155 | } else { |
| 1156 | request.result = false; |
| 1157 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1158 | } |
| 1159 | notifyRequester(request); |
| 1160 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1161 | break; |
| 1162 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1163 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1164 | request = (MainThreadRequest) msg.obj; |
| 1165 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1166 | if (defaultPhone != null) { |
| 1167 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1168 | } else { |
| 1169 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1170 | Bundle bundle = new Bundle(); |
| 1171 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1172 | new ModemActivityInfo(0, 0, 0, |
| 1173 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1174 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1175 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1176 | break; |
| 1177 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1178 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1179 | ar = (AsyncResult) msg.obj; |
| 1180 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1181 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1182 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1183 | ModemActivityInfo ret = null; |
| 1184 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1185 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1186 | // Update the last modem activity info and the result of the request. |
| 1187 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1188 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1189 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1190 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1191 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1192 | .getTransmitTimeMillis(); |
| 1193 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1194 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1195 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1196 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1197 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1198 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1199 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1200 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1201 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1202 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1203 | info.getReceiveTimeMillis() |
| 1204 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1205 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1206 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1207 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1208 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1209 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1210 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1211 | } else { |
| 1212 | if (ar.result == null) { |
| 1213 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1214 | error = TelephonyManager.ModemActivityInfoException |
| 1215 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1216 | } else if (ar.exception instanceof CommandException) { |
| 1217 | loge("queryModemActivityInfo: CommandException: " + |
| 1218 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1219 | error = TelephonyManager.ModemActivityInfoException |
| 1220 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1221 | } else { |
| 1222 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1223 | error = TelephonyManager.ModemActivityInfoException |
| 1224 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1225 | } |
| 1226 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1227 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1228 | if (ret != null) { |
| 1229 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1230 | } else { |
| 1231 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1232 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1233 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1234 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1235 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1236 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1237 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1238 | case CMD_SET_ALLOWED_CARRIERS: |
| 1239 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1240 | CarrierRestrictionRules argument = |
| 1241 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1242 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1243 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1244 | break; |
| 1245 | |
| 1246 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1247 | ar = (AsyncResult) msg.obj; |
| 1248 | request = (MainThreadRequest) ar.userObj; |
| 1249 | if (ar.exception == null && ar.result != null) { |
| 1250 | request.result = ar.result; |
| 1251 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1252 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1253 | if (ar.exception instanceof CommandException) { |
| 1254 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1255 | CommandException.Error error = |
| 1256 | ((CommandException) (ar.exception)).getCommandError(); |
| 1257 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1258 | request.result = |
| 1259 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1260 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1261 | } else { |
| 1262 | loge("setAllowedCarriers: Unknown exception"); |
| 1263 | } |
| 1264 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1265 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1266 | break; |
| 1267 | |
| 1268 | case CMD_GET_ALLOWED_CARRIERS: |
| 1269 | request = (MainThreadRequest) msg.obj; |
| 1270 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1271 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1272 | break; |
| 1273 | |
| 1274 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1275 | ar = (AsyncResult) msg.obj; |
| 1276 | request = (MainThreadRequest) ar.userObj; |
| 1277 | if (ar.exception == null && ar.result != null) { |
| 1278 | request.result = ar.result; |
| 1279 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1280 | request.result = new IllegalStateException( |
| 1281 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1282 | if (ar.result == null) { |
| 1283 | loge("getAllowedCarriers: Empty response"); |
| 1284 | } else if (ar.exception instanceof CommandException) { |
| 1285 | loge("getAllowedCarriers: CommandException: " + |
| 1286 | ar.exception); |
| 1287 | } else { |
| 1288 | loge("getAllowedCarriers: Unknown exception"); |
| 1289 | } |
| 1290 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1291 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1292 | break; |
| 1293 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1294 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1295 | ar = (AsyncResult) msg.obj; |
| 1296 | request = (MainThreadRequest) ar.userObj; |
| 1297 | if (ar.exception == null && ar.result != null) { |
| 1298 | request.result = ar.result; |
| 1299 | } else { |
| 1300 | request.result = new IllegalArgumentException( |
| 1301 | "Failed to retrieve Forbidden Plmns"); |
| 1302 | if (ar.result == null) { |
| 1303 | loge("getForbiddenPlmns: Empty response"); |
| 1304 | } else { |
| 1305 | loge("getForbiddenPlmns: Unknown exception"); |
| 1306 | } |
| 1307 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1308 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1309 | break; |
| 1310 | |
| 1311 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1312 | request = (MainThreadRequest) msg.obj; |
| 1313 | uiccCard = getUiccCardFromRequest(request); |
| 1314 | if (uiccCard == null) { |
| 1315 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1316 | request.result = new IllegalArgumentException( |
| 1317 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1318 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1319 | break; |
| 1320 | } |
| 1321 | Integer appType = (Integer) request.argument; |
| 1322 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1323 | if (uiccApp == null) { |
| 1324 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1325 | + appType); |
| 1326 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1327 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1328 | break; |
| 1329 | } else { |
| 1330 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1331 | + " specified type -- " + appType); |
| 1332 | } |
| 1333 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1334 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1335 | onCompleted); |
| 1336 | break; |
| 1337 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1338 | case CMD_SWITCH_SLOTS: |
| 1339 | request = (MainThreadRequest) msg.obj; |
| 1340 | int[] physicalSlots = (int[]) request.argument; |
| 1341 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1342 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1343 | break; |
| 1344 | |
| 1345 | case EVENT_SWITCH_SLOTS_DONE: |
| 1346 | ar = (AsyncResult) msg.obj; |
| 1347 | request = (MainThreadRequest) ar.userObj; |
| 1348 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1349 | notifyRequester(request); |
| 1350 | break; |
| 1351 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1352 | request = (MainThreadRequest) msg.obj; |
| 1353 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1354 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1355 | break; |
| 1356 | |
| 1357 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1358 | ar = (AsyncResult) msg.obj; |
| 1359 | request = (MainThreadRequest) ar.userObj; |
| 1360 | if (ar.exception != null) { |
| 1361 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1362 | } else { |
| 1363 | int mode = ((int[]) ar.result)[0]; |
| 1364 | if (mode == 0) { |
| 1365 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1366 | } else { |
| 1367 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1368 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1369 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1370 | notifyRequester(request); |
| 1371 | break; |
| 1372 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1373 | request = (MainThreadRequest) msg.obj; |
| 1374 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1375 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1376 | break; |
| 1377 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1378 | ar = (AsyncResult) msg.obj; |
| 1379 | request = (MainThreadRequest) ar.userObj; |
| 1380 | if (ar.exception != null) { |
| 1381 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1382 | } else { |
| 1383 | request.result = ((int[]) ar.result)[0]; |
| 1384 | } |
| 1385 | notifyRequester(request); |
| 1386 | break; |
| 1387 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1388 | request = (MainThreadRequest) msg.obj; |
| 1389 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1390 | int mode = (int) request.argument; |
| 1391 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1392 | break; |
| 1393 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1394 | ar = (AsyncResult) msg.obj; |
| 1395 | request = (MainThreadRequest) ar.userObj; |
| 1396 | request.result = ar.exception == null; |
| 1397 | notifyRequester(request); |
| 1398 | break; |
| 1399 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1400 | request = (MainThreadRequest) msg.obj; |
| 1401 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1402 | int subscriptionMode = (int) request.argument; |
| 1403 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1404 | break; |
| 1405 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1406 | ar = (AsyncResult) msg.obj; |
| 1407 | request = (MainThreadRequest) ar.userObj; |
| 1408 | request.result = ar.exception == null; |
| 1409 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1410 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1411 | case CMD_GET_ALL_CELL_INFO: |
| 1412 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1413 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1414 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1415 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1416 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1417 | ar = (AsyncResult) msg.obj; |
| 1418 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1419 | // If a timeout occurs, the response will be null |
| 1420 | request.result = (ar.exception == null && ar.result != null) |
| 1421 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1422 | synchronized (request) { |
| 1423 | request.notifyAll(); |
| 1424 | } |
| 1425 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1426 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1427 | request = (MainThreadRequest) msg.obj; |
| 1428 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1429 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1430 | break; |
| 1431 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1432 | ar = (AsyncResult) msg.obj; |
| 1433 | request = (MainThreadRequest) ar.userObj; |
| 1434 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1435 | try { |
| 1436 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1437 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1438 | cb.onError( |
| 1439 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1440 | ar.exception.getClass().getName(), |
| 1441 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1442 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1443 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1444 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1445 | } else { |
| 1446 | // use the result as returned |
| 1447 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1448 | } |
| 1449 | } catch (RemoteException re) { |
| 1450 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1451 | } |
| 1452 | break; |
| 1453 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1454 | request = (MainThreadRequest) msg.obj; |
| 1455 | WorkSource ws = (WorkSource) request.argument; |
| 1456 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1457 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1458 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1459 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1460 | ar = (AsyncResult) msg.obj; |
| 1461 | request = (MainThreadRequest) ar.userObj; |
| 1462 | if (ar.exception == null) { |
| 1463 | request.result = ar.result; |
| 1464 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1465 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1466 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1467 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | synchronized (request) { |
| 1471 | request.notifyAll(); |
| 1472 | } |
| 1473 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1474 | case CMD_MODEM_REBOOT: |
| 1475 | request = (MainThreadRequest) msg.obj; |
| 1476 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1477 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1478 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1479 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1480 | handleNullReturnEvent(msg, "rebootModem"); |
| 1481 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1482 | case CMD_REQUEST_ENABLE_MODEM: |
| 1483 | request = (MainThreadRequest) msg.obj; |
| 1484 | boolean enable = (boolean) request.argument; |
| 1485 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1486 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1487 | PhoneConfigurationManager.getInstance() |
| 1488 | .enablePhone(request.phone, enable, onCompleted); |
| 1489 | break; |
| 1490 | case EVENT_ENABLE_MODEM_DONE: |
| 1491 | ar = (AsyncResult) msg.obj; |
| 1492 | request = (MainThreadRequest) ar.userObj; |
| 1493 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1494 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1495 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1496 | if ((boolean) request.result) { |
| 1497 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1498 | updateModemStateMetrics(); |
| 1499 | } else { |
| 1500 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1501 | + ar.exception); |
| 1502 | } |
| 1503 | notifyRequester(request); |
| 1504 | break; |
| 1505 | case CMD_GET_MODEM_STATUS: |
| 1506 | request = (MainThreadRequest) msg.obj; |
| 1507 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1508 | PhoneConfigurationManager.getInstance() |
| 1509 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1510 | break; |
| 1511 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1512 | ar = (AsyncResult) msg.obj; |
| 1513 | request = (MainThreadRequest) ar.userObj; |
| 1514 | int id = request.phone.getPhoneId(); |
| 1515 | if (ar.exception == null && ar.result != null) { |
| 1516 | request.result = ar.result; |
| 1517 | //update the cache as modem status has changed |
| 1518 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1519 | (boolean) request.result); |
| 1520 | } else { |
| 1521 | // Return true if modem status cannot be retrieved. For most cases, |
| 1522 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1523 | // and disable modem are not supported. Modem is always on. |
| 1524 | // TODO: this should be fixed in R to support a third |
| 1525 | // status UNKNOWN b/131631629 |
| 1526 | request.result = true; |
| 1527 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1528 | + ar.exception); |
| 1529 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1530 | notifyRequester(request); |
| 1531 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1532 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1533 | request = (MainThreadRequest) msg.obj; |
| 1534 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1535 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1536 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1537 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1538 | break; |
| 1539 | } |
| 1540 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1541 | ar = (AsyncResult) msg.obj; |
| 1542 | request = (MainThreadRequest) ar.userObj; |
| 1543 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1544 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1545 | args.second.accept(ar.exception == null); |
| 1546 | notifyRequester(request); |
| 1547 | break; |
| 1548 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1549 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1550 | ar = (AsyncResult) msg.obj; |
| 1551 | request = (MainThreadRequest) ar.userObj; |
| 1552 | if (ar.exception == null && ar.result != null) { |
| 1553 | request.result = ar.result; |
| 1554 | } else { |
| 1555 | request.result = -1; |
| 1556 | loge("Failed to set Forbidden Plmns"); |
| 1557 | if (ar.result == null) { |
| 1558 | loge("setForbidenPlmns: Empty response"); |
| 1559 | } else if (ar.exception != null) { |
| 1560 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1561 | request.result = -1; |
| 1562 | } else { |
| 1563 | loge("setForbiddenPlmns: Unknown exception"); |
| 1564 | } |
| 1565 | } |
| 1566 | notifyRequester(request); |
| 1567 | break; |
| 1568 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1569 | request = (MainThreadRequest) msg.obj; |
| 1570 | uiccCard = getUiccCardFromRequest(request); |
| 1571 | if (uiccCard == null) { |
| 1572 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1573 | request.result = -1; |
| 1574 | notifyRequester(request); |
| 1575 | break; |
| 1576 | } |
| 1577 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1578 | (Pair<Integer, List<String>>) request.argument; |
| 1579 | appType = setFplmnsArgs.first; |
| 1580 | List<String> fplmns = setFplmnsArgs.second; |
| 1581 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1582 | if (uiccApp == null) { |
| 1583 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1584 | request.result = -1; |
| 1585 | loge("Failed to get UICC App"); |
| 1586 | notifyRequester(request); |
| 1587 | } else { |
| 1588 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1589 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1590 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1591 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1592 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1593 | case CMD_ERASE_MODEM_CONFIG: |
| 1594 | request = (MainThreadRequest) msg.obj; |
| 1595 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1596 | defaultPhone.eraseModemConfig(onCompleted); |
| 1597 | break; |
| 1598 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1599 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1600 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1601 | |
| 1602 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1603 | request = (MainThreadRequest) msg.obj; |
| 1604 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1605 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1606 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1607 | changed.first, changed.second, onCompleted); |
| 1608 | break; |
| 1609 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1610 | ar = (AsyncResult) msg.obj; |
| 1611 | request = (MainThreadRequest) ar.userObj; |
| 1612 | if (ar.exception == null) { |
| 1613 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1614 | } else { |
| 1615 | request.result = msg.arg1; |
| 1616 | } |
| 1617 | notifyRequester(request); |
| 1618 | break; |
| 1619 | |
| 1620 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1621 | request = (MainThreadRequest) msg.obj; |
| 1622 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1623 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1624 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1625 | enabled.first, enabled.second, onCompleted); |
| 1626 | break; |
| 1627 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1628 | ar = (AsyncResult) msg.obj; |
| 1629 | request = (MainThreadRequest) ar.userObj; |
| 1630 | if (ar.exception == null) { |
| 1631 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1632 | } else { |
| 1633 | request.result = msg.arg1; |
| 1634 | } |
| 1635 | notifyRequester(request); |
| 1636 | break; |
| 1637 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1638 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1639 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1640 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1641 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1642 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1643 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1644 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1645 | default: |
| 1646 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1647 | break; |
| 1648 | } |
| 1649 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1650 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1651 | private void notifyRequester(MainThreadRequest request) { |
| 1652 | synchronized (request) { |
| 1653 | request.notifyAll(); |
| 1654 | } |
| 1655 | } |
| 1656 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1657 | private void handleNullReturnEvent(Message msg, String command) { |
| 1658 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1659 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1660 | if (ar.exception == null) { |
| 1661 | request.result = true; |
| 1662 | } else { |
| 1663 | request.result = false; |
| 1664 | if (ar.exception instanceof CommandException) { |
| 1665 | loge(command + ": CommandException: " + ar.exception); |
| 1666 | } else { |
| 1667 | loge(command + ": Unknown exception"); |
| 1668 | } |
| 1669 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1670 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1671 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | /** |
| 1675 | * Posts the specified command to be executed on the main thread, |
| 1676 | * waits for the request to complete, and returns the result. |
| 1677 | * @see #sendRequestAsync |
| 1678 | */ |
| 1679 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1680 | return sendRequest( |
| 1681 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | /** |
| 1685 | * Posts the specified command to be executed on the main thread, |
| 1686 | * waits for the request to complete, and returns the result. |
| 1687 | * @see #sendRequestAsync |
| 1688 | */ |
| 1689 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1690 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1691 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | /** |
| 1695 | * Posts the specified command to be executed on the main thread, |
| 1696 | * waits for the request to complete, and returns the result. |
| 1697 | * @see #sendRequestAsync |
| 1698 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1699 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1700 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | /** |
| 1704 | * Posts the specified command to be executed on the main thread, |
| 1705 | * waits for the request to complete, and returns the result. |
| 1706 | * @see #sendRequestAsync |
| 1707 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1708 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1709 | return sendRequest(command, argument, subId, null, workSource); |
| 1710 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * Posts the specified command to be executed on the main thread, |
| 1714 | * waits for the request to complete, and returns the result. |
| 1715 | * @see #sendRequestAsync |
| 1716 | */ |
| 1717 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1718 | return sendRequest( |
| 1719 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1720 | } |
| 1721 | |
| 1722 | /** |
| 1723 | * Posts the specified command to be executed on the main thread, |
| 1724 | * waits for the request to complete, and returns the result. |
| 1725 | * @see #sendRequestAsync |
| 1726 | */ |
| 1727 | private Object sendRequest( |
| 1728 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1729 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1730 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1731 | } |
| 1732 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1733 | MainThreadRequest request = null; |
| 1734 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1735 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1736 | } else if (phone != null) { |
| 1737 | request = new MainThreadRequest(argument, phone, workSource); |
| 1738 | } else { |
| 1739 | request = new MainThreadRequest(argument, subId, workSource); |
| 1740 | } |
| 1741 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1742 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1743 | msg.sendToTarget(); |
| 1744 | |
| 1745 | // Wait for the request to complete |
| 1746 | synchronized (request) { |
| 1747 | while (request.result == null) { |
| 1748 | try { |
| 1749 | request.wait(); |
| 1750 | } catch (InterruptedException e) { |
| 1751 | // Do nothing, go back and wait until the request is complete |
| 1752 | } |
| 1753 | } |
| 1754 | } |
| 1755 | return request.result; |
| 1756 | } |
| 1757 | |
| 1758 | /** |
| 1759 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1760 | * Posts the specified command to be executed on the main thread, and |
| 1761 | * returns immediately. |
| 1762 | * @see #sendRequest |
| 1763 | */ |
| 1764 | private void sendRequestAsync(int command) { |
| 1765 | mMainThreadHandler.sendEmptyMessage(command); |
| 1766 | } |
| 1767 | |
| 1768 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1769 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1770 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1771 | */ |
| 1772 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1773 | sendRequestAsync(command, argument, null, null); |
| 1774 | } |
| 1775 | |
| 1776 | /** |
| 1777 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1778 | * @see {@link #sendRequest(int,Object)} |
| 1779 | */ |
| 1780 | private void sendRequestAsync( |
| 1781 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1782 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1783 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1784 | msg.sendToTarget(); |
| 1785 | } |
| 1786 | |
| 1787 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1788 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1789 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1790 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1791 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1792 | synchronized (PhoneInterfaceManager.class) { |
| 1793 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1794 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1795 | } else { |
| 1796 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1797 | } |
| 1798 | return sInstance; |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1803 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1804 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1805 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1806 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1807 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1808 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1809 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1810 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1811 | mTelephonySharedPreferences = |
| 1812 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1813 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1814 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1815 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1816 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1817 | publish(); |
| 1818 | } |
| 1819 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1820 | private Phone getDefaultPhone() { |
| 1821 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1822 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1823 | } |
| 1824 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1825 | private void publish() { |
| 1826 | if (DBG) log("publish: " + this); |
| 1827 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1828 | TelephonyFrameworkInitializer |
| 1829 | .getTelephonyServiceManager() |
| 1830 | .getTelephonyServiceRegisterer() |
| 1831 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1834 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1835 | if (request.phone != null) { |
| 1836 | return request.phone; |
| 1837 | } else { |
| 1838 | return getPhoneFromSubId(request.subId); |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | private Phone getPhoneFromSubId(int subId) { |
| 1843 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1844 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1845 | } |
| 1846 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1847 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1848 | Phone phone = getPhoneFromRequest(request); |
| 1849 | return phone == null ? null : |
| 1850 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1851 | } |
| 1852 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1853 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1854 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1855 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1856 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1857 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1858 | private void sendEraseModemConfig(Phone phone) { |
| 1859 | if (phone != null) { |
| 1860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1861 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1862 | final long identity = Binder.clearCallingIdentity(); |
| 1863 | try { |
| 1864 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1865 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1866 | } finally { |
| 1867 | Binder.restoreCallingIdentity(identity); |
| 1868 | } |
| 1869 | } |
| 1870 | } |
| 1871 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1872 | private boolean isImsAvailableOnDevice() { |
| 1873 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1874 | if (pm == null) { |
| 1875 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1876 | // so do not throw error and allow. |
| 1877 | return true; |
| 1878 | } |
| 1879 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1880 | } |
| 1881 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1882 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1883 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1886 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1887 | if (DBG) log("dial: " + number); |
| 1888 | // No permission check needed here: This is just a wrapper around the |
| 1889 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1890 | // the UI before it does anything. |
| 1891 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1892 | final long identity = Binder.clearCallingIdentity(); |
| 1893 | try { |
| 1894 | String url = createTelUrl(number); |
| 1895 | if (url == null) { |
| 1896 | return; |
| 1897 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1898 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1899 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1900 | PhoneConstants.State state = mCM.getState(subId); |
| 1901 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1902 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1903 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1904 | mApp.startActivity(intent); |
| 1905 | } |
| 1906 | } finally { |
| 1907 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1908 | } |
| 1909 | } |
| 1910 | |
| 1911 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1912 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1915 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1916 | if (DBG) log("call: " + number); |
| 1917 | |
| 1918 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1919 | // need to do a permission check since we're calling startActivity() |
| 1920 | // from the context of the phone app. |
| 1921 | enforceCallPermission(); |
| 1922 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1923 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1924 | != AppOpsManager.MODE_ALLOWED) { |
| 1925 | return; |
| 1926 | } |
| 1927 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1928 | final long identity = Binder.clearCallingIdentity(); |
| 1929 | try { |
| 1930 | String url = createTelUrl(number); |
| 1931 | if (url == null) { |
| 1932 | return; |
| 1933 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1935 | boolean isValid = false; |
| 1936 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1937 | if (slist != null) { |
| 1938 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1939 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1940 | isValid = true; |
| 1941 | break; |
| 1942 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1943 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1944 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1945 | if (!isValid) { |
| 1946 | return; |
| 1947 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1948 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1949 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1950 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1951 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1952 | mApp.startActivity(intent); |
| 1953 | } finally { |
| 1954 | Binder.restoreCallingIdentity(identity); |
| 1955 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1958 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1959 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1960 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1961 | } |
| 1962 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1963 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1964 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1965 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1966 | } |
| 1967 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1968 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1969 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1970 | |
| 1971 | final long identity = Binder.clearCallingIdentity(); |
| 1972 | try { |
| 1973 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1974 | checkSimPin.start(); |
| 1975 | return checkSimPin.unlockSim(null, pin); |
| 1976 | } finally { |
| 1977 | Binder.restoreCallingIdentity(identity); |
| 1978 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1981 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1983 | |
| 1984 | final long identity = Binder.clearCallingIdentity(); |
| 1985 | try { |
| 1986 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1987 | checkSimPuk.start(); |
| 1988 | return checkSimPuk.unlockSim(puk, pin); |
| 1989 | } finally { |
| 1990 | Binder.restoreCallingIdentity(identity); |
| 1991 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1995 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1996 | * a synchronous one. |
| 1997 | */ |
| 1998 | private static class UnlockSim extends Thread { |
| 1999 | |
| 2000 | private final IccCard mSimCard; |
| 2001 | |
| 2002 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2003 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2004 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2005 | |
| 2006 | // For replies from SimCard interface |
| 2007 | private Handler mHandler; |
| 2008 | |
| 2009 | // For async handler to identify request type |
| 2010 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2011 | |
| 2012 | public UnlockSim(IccCard simCard) { |
| 2013 | mSimCard = simCard; |
| 2014 | } |
| 2015 | |
| 2016 | @Override |
| 2017 | public void run() { |
| 2018 | Looper.prepare(); |
| 2019 | synchronized (UnlockSim.this) { |
| 2020 | mHandler = new Handler() { |
| 2021 | @Override |
| 2022 | public void handleMessage(Message msg) { |
| 2023 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2024 | switch (msg.what) { |
| 2025 | case SUPPLY_PIN_COMPLETE: |
| 2026 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2027 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2028 | mRetryCount = msg.arg1; |
| 2029 | if (ar.exception != null) { |
| 2030 | if (ar.exception instanceof CommandException && |
| 2031 | ((CommandException)(ar.exception)).getCommandError() |
| 2032 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2033 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2034 | } //When UiccCardApp dispose,handle message and return exception |
| 2035 | else if (ar.exception instanceof CommandException && |
| 2036 | ((CommandException) (ar.exception)).getCommandError() |
| 2037 | == CommandException.Error.ABORTED) { |
| 2038 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2039 | } else { |
| 2040 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2041 | } |
| 2042 | } else { |
| 2043 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2044 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2045 | mDone = true; |
| 2046 | UnlockSim.this.notifyAll(); |
| 2047 | } |
| 2048 | break; |
| 2049 | } |
| 2050 | } |
| 2051 | }; |
| 2052 | UnlockSim.this.notifyAll(); |
| 2053 | } |
| 2054 | Looper.loop(); |
| 2055 | } |
| 2056 | |
| 2057 | /* |
| 2058 | * Use PIN or PUK to unlock SIM card |
| 2059 | * |
| 2060 | * If PUK is null, unlock SIM card with PIN |
| 2061 | * |
| 2062 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2063 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2064 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2065 | |
| 2066 | while (mHandler == null) { |
| 2067 | try { |
| 2068 | wait(); |
| 2069 | } catch (InterruptedException e) { |
| 2070 | Thread.currentThread().interrupt(); |
| 2071 | } |
| 2072 | } |
| 2073 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2074 | |
| 2075 | if (puk == null) { |
| 2076 | mSimCard.supplyPin(pin, callback); |
| 2077 | } else { |
| 2078 | mSimCard.supplyPuk(puk, pin, callback); |
| 2079 | } |
| 2080 | |
| 2081 | while (!mDone) { |
| 2082 | try { |
| 2083 | Log.d(LOG_TAG, "wait for done"); |
| 2084 | wait(); |
| 2085 | } catch (InterruptedException e) { |
| 2086 | // Restore the interrupted status |
| 2087 | Thread.currentThread().interrupt(); |
| 2088 | } |
| 2089 | } |
| 2090 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2091 | int[] resultArray = new int[2]; |
| 2092 | resultArray[0] = mResult; |
| 2093 | resultArray[1] = mRetryCount; |
| 2094 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | } |
| 2096 | } |
| 2097 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2098 | /** |
| 2099 | * This method has been removed due to privacy and stability concerns. |
| 2100 | */ |
| 2101 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2102 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2103 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2104 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2107 | @Override |
| 2108 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2109 | mApp.getSystemService(AppOpsManager.class) |
| 2110 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2111 | |
| 2112 | final int targetSdk = getTargetSdk(callingPackage); |
| 2113 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2114 | // Callers targeting S have no business invoking this method. |
| 2115 | return; |
| 2116 | } |
| 2117 | |
| 2118 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2119 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2120 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2121 | .setCallingPackage(callingPackage) |
| 2122 | .setCallingFeatureId(null) |
| 2123 | .setCallingPid(Binder.getCallingPid()) |
| 2124 | .setCallingUid(Binder.getCallingUid()) |
| 2125 | .setMethod("updateServiceLocation") |
| 2126 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2127 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2128 | .build()); |
| 2129 | // Apps that lack location permission have no business calling this method; |
| 2130 | // however, because no permission was declared in the public API, denials must |
| 2131 | // all be "soft". |
| 2132 | switch (locationResult) { |
| 2133 | case DENIED_HARD: /* fall through */ |
| 2134 | case DENIED_SOFT: |
| 2135 | return; |
| 2136 | } |
| 2137 | |
| 2138 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2139 | final long identity = Binder.clearCallingIdentity(); |
| 2140 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2141 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2142 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2143 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2144 | } |
| 2145 | } finally { |
| 2146 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2147 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2150 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2151 | @Override |
| 2152 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2153 | return isRadioOnWithFeature(callingPackage, null); |
| 2154 | } |
| 2155 | |
| 2156 | |
| 2157 | @Override |
| 2158 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2159 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2160 | callingFeatureId); |
| 2161 | } |
| 2162 | |
| 2163 | @Deprecated |
| 2164 | @Override |
| 2165 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2166 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2169 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2170 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2171 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2172 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2173 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2174 | return false; |
| 2175 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2176 | |
| 2177 | final long identity = Binder.clearCallingIdentity(); |
| 2178 | try { |
| 2179 | return isRadioOnForSubscriber(subId); |
| 2180 | } finally { |
| 2181 | Binder.restoreCallingIdentity(identity); |
| 2182 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2186 | final long identity = Binder.clearCallingIdentity(); |
| 2187 | try { |
| 2188 | final Phone phone = getPhone(subId); |
| 2189 | if (phone != null) { |
| 2190 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2191 | } else { |
| 2192 | return false; |
| 2193 | } |
| 2194 | } finally { |
| 2195 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2200 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2201 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2202 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2203 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2204 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2205 | |
| 2206 | final long identity = Binder.clearCallingIdentity(); |
| 2207 | try { |
| 2208 | final Phone phone = getPhone(subId); |
| 2209 | if (phone != null) { |
| 2210 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2211 | } |
| 2212 | } finally { |
| 2213 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2214 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2218 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2221 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2222 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2223 | |
| 2224 | final long identity = Binder.clearCallingIdentity(); |
| 2225 | try { |
| 2226 | final Phone phone = getPhone(subId); |
| 2227 | if (phone == null) { |
| 2228 | return false; |
| 2229 | } |
| 2230 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2231 | toggleRadioOnOffForSubscriber(subId); |
| 2232 | } |
| 2233 | return true; |
| 2234 | } finally { |
| 2235 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2236 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2237 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2238 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2239 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2240 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2241 | /* |
| 2242 | * If any of the Radios are available, it will need to be |
| 2243 | * shutdown. So return true if any Radio is available. |
| 2244 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2245 | final long identity = Binder.clearCallingIdentity(); |
| 2246 | try { |
| 2247 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2248 | Phone phone = PhoneFactory.getPhone(i); |
| 2249 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2250 | } |
| 2251 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2252 | return false; |
| 2253 | } finally { |
| 2254 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2255 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2259 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2260 | enforceModifyPermission(); |
| 2261 | |
| 2262 | final long identity = Binder.clearCallingIdentity(); |
| 2263 | try { |
| 2264 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2265 | logv("Shutting down Phone " + i); |
| 2266 | shutdownRadioUsingPhoneId(i); |
| 2267 | } |
| 2268 | } finally { |
| 2269 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2274 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2275 | if (phone != null && phone.isRadioAvailable()) { |
| 2276 | phone.shutdownRadio(); |
| 2277 | } |
| 2278 | } |
| 2279 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2281 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2282 | |
| 2283 | final long identity = Binder.clearCallingIdentity(); |
| 2284 | try { |
| 2285 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2286 | if (defaultPhone != null) { |
| 2287 | defaultPhone.setRadioPower(turnOn); |
| 2288 | return true; |
| 2289 | } else { |
| 2290 | loge("There's no default phone."); |
| 2291 | return false; |
| 2292 | } |
| 2293 | } finally { |
| 2294 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2295 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2298 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2299 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2300 | |
| 2301 | final long identity = Binder.clearCallingIdentity(); |
| 2302 | try { |
| 2303 | final Phone phone = getPhone(subId); |
| 2304 | if (phone != null) { |
| 2305 | phone.setRadioPower(turnOn); |
| 2306 | return true; |
| 2307 | } else { |
| 2308 | return false; |
| 2309 | } |
| 2310 | } finally { |
| 2311 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2312 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2315 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2316 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2317 | public boolean enableDataConnectivity() { |
| 2318 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2319 | |
| 2320 | final long identity = Binder.clearCallingIdentity(); |
| 2321 | try { |
| 2322 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2323 | final Phone phone = getPhone(subId); |
| 2324 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2325 | phone.getDataEnabledSettings().setDataEnabled( |
| 2326 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2327 | return true; |
| 2328 | } else { |
| 2329 | return false; |
| 2330 | } |
| 2331 | } finally { |
| 2332 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2333 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2336 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2337 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2338 | public boolean disableDataConnectivity() { |
| 2339 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2340 | |
| 2341 | final long identity = Binder.clearCallingIdentity(); |
| 2342 | try { |
| 2343 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2344 | final Phone phone = getPhone(subId); |
| 2345 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2346 | phone.getDataEnabledSettings().setDataEnabled( |
| 2347 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2348 | return true; |
| 2349 | } else { |
| 2350 | return false; |
| 2351 | } |
| 2352 | } finally { |
| 2353 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2354 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2357 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2358 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2359 | final long identity = Binder.clearCallingIdentity(); |
| 2360 | try { |
| 2361 | final Phone phone = getPhone(subId); |
| 2362 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2363 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | } else { |
| 2365 | return false; |
| 2366 | } |
| 2367 | } finally { |
| 2368 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2369 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2370 | } |
| 2371 | |
| 2372 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2373 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2376 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2377 | enforceCallPermission(); |
| 2378 | |
| 2379 | final long identity = Binder.clearCallingIdentity(); |
| 2380 | try { |
| 2381 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2382 | return; |
| 2383 | } |
| 2384 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2385 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2386 | } finally { |
| 2387 | Binder.restoreCallingIdentity(identity); |
| 2388 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2389 | }; |
| 2390 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2391 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2393 | |
| 2394 | final long identity = Binder.clearCallingIdentity(); |
| 2395 | try { |
| 2396 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2397 | return false; |
| 2398 | } |
| 2399 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2400 | } finally { |
| 2401 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2406 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2409 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2410 | final long identity = Binder.clearCallingIdentity(); |
| 2411 | try { |
| 2412 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2413 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2414 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2415 | } finally { |
| 2416 | Binder.restoreCallingIdentity(identity); |
| 2417 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2420 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2421 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2422 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2423 | } |
| 2424 | |
| 2425 | @Override |
| 2426 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2427 | final long identity = Binder.clearCallingIdentity(); |
| 2428 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2429 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2430 | if (phone != null) { |
| 2431 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2432 | } else { |
| 2433 | return PhoneConstantConversions.convertDataState( |
| 2434 | PhoneConstants.DataState.DISCONNECTED); |
| 2435 | } |
| 2436 | } finally { |
| 2437 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2438 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | } |
| 2440 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2441 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2442 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2443 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2444 | } |
| 2445 | |
| 2446 | @Override |
| 2447 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | final long identity = Binder.clearCallingIdentity(); |
| 2449 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2450 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2451 | if (phone != null) { |
| 2452 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2453 | } else { |
| 2454 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2455 | } |
| 2456 | } finally { |
| 2457 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2458 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2462 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2463 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2464 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2465 | |
| 2466 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2467 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2468 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2469 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2470 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2471 | .setCallingPid(Binder.getCallingPid()) |
| 2472 | .setCallingUid(Binder.getCallingUid()) |
| 2473 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2474 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2475 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2476 | .build()); |
| 2477 | switch (locationResult) { |
| 2478 | case DENIED_HARD: |
| 2479 | throw new SecurityException("Not allowed to access cell location"); |
| 2480 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2481 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2482 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2485 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2486 | final long identity = Binder.clearCallingIdentity(); |
| 2487 | try { |
| 2488 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2489 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2490 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2491 | } finally { |
| 2492 | Binder.restoreCallingIdentity(identity); |
| 2493 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2497 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2498 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2499 | // registered cell info, so return a NULL country instead. |
| 2500 | final long identity = Binder.clearCallingIdentity(); |
| 2501 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2502 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2503 | // Get default phone in this case. |
| 2504 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2505 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2506 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2508 | if (phone == null) return ""; |
| 2509 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2510 | if (sst == null) return ""; |
| 2511 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2512 | if (lt == null) return ""; |
| 2513 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2514 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2515 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2516 | } finally { |
| 2517 | Binder.restoreCallingIdentity(identity); |
| 2518 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2521 | /** |
| 2522 | * This method was removed due to potential issues caused by performing partial |
| 2523 | * updates of service state, and lack of a credible use case. |
| 2524 | * |
| 2525 | * This has the ability to break the telephony implementation by disabling notification of |
| 2526 | * changes in device connectivity. DO NOT USE THIS! |
| 2527 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2528 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2529 | public void enableLocationUpdates() { |
| 2530 | mApp.enforceCallingOrSelfPermission( |
| 2531 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2534 | /** |
| 2535 | * This method was removed due to potential issues caused by performing partial |
| 2536 | * updates of service state, and lack of a credible use case. |
| 2537 | * |
| 2538 | * This has the ability to break the telephony implementation by disabling notification of |
| 2539 | * changes in device connectivity. DO NOT USE THIS! |
| 2540 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | @Override |
| 2542 | public void disableLocationUpdates() { |
| 2543 | mApp.enforceCallingOrSelfPermission( |
| 2544 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2547 | /** |
| 2548 | * Returns the target SDK version number for a given package name. |
| 2549 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2550 | * This call MUST be invoked before clearing the calling UID. |
| 2551 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2552 | * @return target SDK if the package is found or INT_MAX. |
| 2553 | */ |
| 2554 | private int getTargetSdk(String packageName) { |
| 2555 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2556 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2557 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2558 | if (ai != null) return ai.targetSdkVersion; |
| 2559 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2560 | loge("Failed to get package info for pkg=" |
| 2561 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2562 | } |
| 2563 | return Integer.MAX_VALUE; |
| 2564 | } |
| 2565 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2566 | @Override |
| 2567 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2568 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2569 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2570 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2571 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2572 | throw new SecurityException( |
| 2573 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2574 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2575 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2576 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2577 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2578 | return null; |
| 2579 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2580 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2581 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2582 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2583 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2584 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2585 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2586 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2587 | for (CellInfo ci : info) { |
| 2588 | if (ci instanceof CellInfoGsm) { |
| 2589 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2590 | } else if (ci instanceof CellInfoWcdma) { |
| 2591 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2592 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2593 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2594 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2597 | private List<CellInfo> getCachedCellInfo() { |
| 2598 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2599 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2600 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2601 | if (info != null) cellInfos.addAll(info); |
| 2602 | } |
| 2603 | return cellInfos; |
| 2604 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | |
| 2606 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2607 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2608 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2609 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2610 | |
| 2611 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2612 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2613 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2614 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2615 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2616 | .setCallingPid(Binder.getCallingPid()) |
| 2617 | .setCallingUid(Binder.getCallingUid()) |
| 2618 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2619 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2620 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2621 | .build()); |
| 2622 | switch (locationResult) { |
| 2623 | case DENIED_HARD: |
| 2624 | throw new SecurityException("Not allowed to access cell info"); |
| 2625 | case DENIED_SOFT: |
| 2626 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2629 | final int targetSdk = getTargetSdk(callingPackage); |
| 2630 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2631 | return getCachedCellInfo(); |
| 2632 | } |
| 2633 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2634 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2635 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | final long identity = Binder.clearCallingIdentity(); |
| 2637 | try { |
| 2638 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2639 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2640 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2641 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | if (info != null) cellInfos.addAll(info); |
| 2643 | } |
| 2644 | return cellInfos; |
| 2645 | } finally { |
| 2646 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | } |
| 2648 | } |
| 2649 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2650 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2651 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2652 | String callingFeatureId) { |
| 2653 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2654 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2658 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2659 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2660 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2661 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2664 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2665 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2666 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2667 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2668 | |
| 2669 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2670 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2671 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2672 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2673 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2674 | .setCallingPid(Binder.getCallingPid()) |
| 2675 | .setCallingUid(Binder.getCallingUid()) |
| 2676 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2677 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2678 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2679 | .build()); |
| 2680 | switch (locationResult) { |
| 2681 | case DENIED_HARD: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2682 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2683 | // Safetynet logging for b/154934934 |
| 2684 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2685 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2686 | throw new SecurityException("Not allowed to access cell info"); |
| 2687 | case DENIED_SOFT: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2688 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2689 | // Safetynet logging for b/154934934 |
| 2690 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2691 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2692 | try { |
| 2693 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2694 | } catch (RemoteException re) { |
| 2695 | // Drop without consequences |
| 2696 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2697 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2700 | |
| 2701 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2702 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2703 | |
| 2704 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2705 | } |
| 2706 | |
| 2707 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2709 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2710 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2711 | |
| 2712 | final long identity = Binder.clearCallingIdentity(); |
| 2713 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2714 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
| 2717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2720 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2721 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2722 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2723 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2724 | return null; |
| 2725 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2726 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2727 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2728 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2729 | return null; |
| 2730 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2731 | |
| 2732 | final long identity = Binder.clearCallingIdentity(); |
| 2733 | try { |
| 2734 | return phone.getImei(); |
| 2735 | } finally { |
| 2736 | Binder.restoreCallingIdentity(identity); |
| 2737 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2741 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2742 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2743 | String tac = null; |
| 2744 | if (phone != null) { |
| 2745 | String imei = phone.getImei(); |
| 2746 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2747 | } |
| 2748 | return tac; |
| 2749 | } |
| 2750 | |
| 2751 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2752 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2753 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2754 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2755 | return null; |
| 2756 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2757 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2758 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2759 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2760 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2761 | return null; |
| 2762 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2763 | |
| 2764 | final long identity = Binder.clearCallingIdentity(); |
| 2765 | try { |
| 2766 | return phone.getMeid(); |
| 2767 | } finally { |
| 2768 | Binder.restoreCallingIdentity(identity); |
| 2769 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2773 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2774 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2775 | String manufacturerCode = null; |
| 2776 | if (phone != null) { |
| 2777 | String meid = phone.getMeid(); |
| 2778 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2779 | } |
| 2780 | return manufacturerCode; |
| 2781 | } |
| 2782 | |
| 2783 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2784 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2785 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2786 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2787 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2788 | return null; |
| 2789 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2790 | int subId = phone.getSubId(); |
| 2791 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2792 | mApp, subId, callingPackage, callingFeatureId, |
| 2793 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2794 | return null; |
| 2795 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2796 | |
| 2797 | final long identity = Binder.clearCallingIdentity(); |
| 2798 | try { |
| 2799 | return phone.getDeviceSvn(); |
| 2800 | } finally { |
| 2801 | Binder.restoreCallingIdentity(identity); |
| 2802 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2803 | } |
| 2804 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2805 | @Override |
| 2806 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2807 | final long identity = Binder.clearCallingIdentity(); |
| 2808 | try { |
| 2809 | final Phone phone = getPhone(subId); |
| 2810 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2811 | } finally { |
| 2812 | Binder.restoreCallingIdentity(identity); |
| 2813 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | @Override |
| 2817 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2818 | final long identity = Binder.clearCallingIdentity(); |
| 2819 | try { |
| 2820 | final Phone phone = getPhone(subId); |
| 2821 | return phone == null ? null : phone.getCarrierName(); |
| 2822 | } finally { |
| 2823 | Binder.restoreCallingIdentity(identity); |
| 2824 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2825 | } |
| 2826 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2827 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2828 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
| 2831 | final Phone phone = getPhone(subId); |
| 2832 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2833 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2834 | } finally { |
| 2835 | Binder.restoreCallingIdentity(identity); |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2840 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2841 | final long identity = Binder.clearCallingIdentity(); |
| 2842 | try { |
| 2843 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2844 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2845 | } finally { |
| 2846 | Binder.restoreCallingIdentity(identity); |
| 2847 | } |
| 2848 | } |
| 2849 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2850 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2851 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2852 | if (!isSubscriptionMccMnc) { |
| 2853 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2854 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2855 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2856 | if (phone == null) { |
| 2857 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2858 | } |
| 2859 | final long identity = Binder.clearCallingIdentity(); |
| 2860 | try { |
| 2861 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2862 | } finally { |
| 2863 | Binder.restoreCallingIdentity(identity); |
| 2864 | } |
| 2865 | } |
| 2866 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2867 | // |
| 2868 | // Internal helper methods. |
| 2869 | // |
| 2870 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2871 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2872 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2873 | * |
| 2874 | * @throws SecurityException if the caller does not have the required permission |
| 2875 | */ |
| 2876 | private void enforceModifyPermission() { |
| 2877 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2878 | } |
| 2879 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2880 | /** |
| 2881 | * Make sure the caller is system. |
| 2882 | * |
| 2883 | * @throws SecurityException if the caller is not system. |
| 2884 | */ |
| 2885 | private void enforceSystemCaller() { |
| 2886 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2887 | throw new SecurityException("Caller must be system"); |
| 2888 | } |
| 2889 | } |
| 2890 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2891 | private void enforceActiveEmergencySessionPermission() { |
| 2892 | mApp.enforceCallingOrSelfPermission( |
| 2893 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2894 | } |
| 2895 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2896 | /** |
| 2897 | * Make sure the caller has the CALL_PHONE permission. |
| 2898 | * |
| 2899 | * @throws SecurityException if the caller does not have the required permission |
| 2900 | */ |
| 2901 | private void enforceCallPermission() { |
| 2902 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2903 | } |
| 2904 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2905 | private void enforceSettingsPermission() { |
| 2906 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2907 | } |
| 2908 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2909 | private String createTelUrl(String number) { |
| 2910 | if (TextUtils.isEmpty(number)) { |
| 2911 | return null; |
| 2912 | } |
| 2913 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2914 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2915 | } |
| 2916 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2917 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2918 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2919 | } |
| 2920 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2921 | private static void logv(String msg) { |
| 2922 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2923 | } |
| 2924 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2925 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2926 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2927 | } |
| 2928 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2929 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2930 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2931 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2932 | } |
| 2933 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2934 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2935 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | final long identity = Binder.clearCallingIdentity(); |
| 2937 | try { |
| 2938 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2939 | if (phone == null) { |
| 2940 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2941 | } else { |
| 2942 | return phone.getPhoneType(); |
| 2943 | } |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2946 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | /** |
| 2950 | * Returns the CDMA ERI icon index to display |
| 2951 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2952 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2953 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2954 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2955 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2956 | } |
| 2957 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2958 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2959 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2960 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2961 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2962 | mApp, subId, callingPackage, callingFeatureId, |
| 2963 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2964 | return -1; |
| 2965 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2966 | |
| 2967 | final long identity = Binder.clearCallingIdentity(); |
| 2968 | try { |
| 2969 | final Phone phone = getPhone(subId); |
| 2970 | if (phone != null) { |
| 2971 | return phone.getCdmaEriIconIndex(); |
| 2972 | } else { |
| 2973 | return -1; |
| 2974 | } |
| 2975 | } finally { |
| 2976 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2977 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | /** |
| 2981 | * Returns the CDMA ERI icon mode, |
| 2982 | * 0 - ON |
| 2983 | * 1 - FLASHING |
| 2984 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2985 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2986 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2987 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2988 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2991 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2992 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2993 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2994 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2995 | mApp, subId, callingPackage, callingFeatureId, |
| 2996 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2997 | return -1; |
| 2998 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2999 | |
| 3000 | final long identity = Binder.clearCallingIdentity(); |
| 3001 | try { |
| 3002 | final Phone phone = getPhone(subId); |
| 3003 | if (phone != null) { |
| 3004 | return phone.getCdmaEriIconMode(); |
| 3005 | } else { |
| 3006 | return -1; |
| 3007 | } |
| 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3010 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | /** |
| 3014 | * Returns the CDMA ERI text, |
| 3015 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3016 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3017 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3018 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3019 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3022 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3023 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3024 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3025 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3026 | mApp, subId, callingPackage, callingFeatureId, |
| 3027 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3028 | return null; |
| 3029 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | |
| 3031 | final long identity = Binder.clearCallingIdentity(); |
| 3032 | try { |
| 3033 | final Phone phone = getPhone(subId); |
| 3034 | if (phone != null) { |
| 3035 | return phone.getCdmaEriText(); |
| 3036 | } else { |
| 3037 | return null; |
| 3038 | } |
| 3039 | } finally { |
| 3040 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3041 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3045 | * Returns the CDMA MDN. |
| 3046 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3047 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3048 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3050 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | |
| 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
| 3054 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3055 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3056 | return phone.getLine1Number(); |
| 3057 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3058 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3059 | return null; |
| 3060 | } |
| 3061 | } finally { |
| 3062 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | /** |
| 3067 | * Returns the CDMA MIN. |
| 3068 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3069 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3070 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3072 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3073 | |
| 3074 | final long identity = Binder.clearCallingIdentity(); |
| 3075 | try { |
| 3076 | final Phone phone = getPhone(subId); |
| 3077 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3078 | return phone.getCdmaMin(); |
| 3079 | } else { |
| 3080 | return null; |
| 3081 | } |
| 3082 | } finally { |
| 3083 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3084 | } |
| 3085 | } |
| 3086 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3087 | @Override |
| 3088 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3089 | INumberVerificationCallback callback, String callingPackage) { |
| 3090 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3091 | != PERMISSION_GRANTED) { |
| 3092 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3093 | } |
| 3094 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3095 | |
| 3096 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3097 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3098 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3099 | } |
| 3100 | |
| 3101 | if (range == null) { |
| 3102 | throw new NullPointerException("Range must be non-null"); |
| 3103 | } |
| 3104 | |
| 3105 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3106 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3107 | |
| 3108 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3109 | } |
| 3110 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3111 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3112 | * Returns true if CDMA provisioning needs to run. |
| 3113 | */ |
| 3114 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3115 | final long identity = Binder.clearCallingIdentity(); |
| 3116 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3117 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3118 | } finally { |
| 3119 | Binder.restoreCallingIdentity(identity); |
| 3120 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3124 | * Sets the voice mail number of a given subId. |
| 3125 | */ |
| 3126 | @Override |
| 3127 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3128 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3129 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3130 | |
| 3131 | final long identity = Binder.clearCallingIdentity(); |
| 3132 | try { |
| 3133 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3134 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3135 | return success; |
| 3136 | } finally { |
| 3137 | Binder.restoreCallingIdentity(identity); |
| 3138 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3139 | } |
| 3140 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3141 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3142 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3143 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3144 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3145 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3146 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3147 | throw new SecurityException("caller must be system dialer"); |
| 3148 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3149 | |
| 3150 | final long identity = Binder.clearCallingIdentity(); |
| 3151 | try { |
| 3152 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3153 | if (phoneAccountHandle == null) { |
| 3154 | return null; |
| 3155 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3156 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3159 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3163 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3164 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3165 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3166 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3167 | mApp, subId, callingPackage, callingFeatureId, |
| 3168 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3169 | return null; |
| 3170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3171 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3172 | final long identity = Binder.clearCallingIdentity(); |
| 3173 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3174 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3175 | } finally { |
| 3176 | Binder.restoreCallingIdentity(identity); |
| 3177 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3181 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3182 | VisualVoicemailSmsFilterSettings settings) { |
| 3183 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3184 | |
| 3185 | final long identity = Binder.clearCallingIdentity(); |
| 3186 | try { |
| 3187 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3188 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | } finally { |
| 3190 | Binder.restoreCallingIdentity(identity); |
| 3191 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3195 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3196 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3197 | |
| 3198 | final long identity = Binder.clearCallingIdentity(); |
| 3199 | try { |
| 3200 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3201 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3202 | } finally { |
| 3203 | Binder.restoreCallingIdentity(identity); |
| 3204 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3208 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3209 | String callingPackage, int subId) { |
| 3210 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3211 | |
| 3212 | final long identity = Binder.clearCallingIdentity(); |
| 3213 | try { |
| 3214 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3215 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3216 | } finally { |
| 3217 | Binder.restoreCallingIdentity(identity); |
| 3218 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3222 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3223 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | |
| 3225 | final long identity = Binder.clearCallingIdentity(); |
| 3226 | try { |
| 3227 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3228 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
| 3231 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3235 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3236 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3237 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3238 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3239 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3240 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3241 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3242 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3243 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3244 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3245 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3246 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3247 | * Sets the voice activation state of a given subId. |
| 3248 | */ |
| 3249 | @Override |
| 3250 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3252 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3253 | |
| 3254 | final long identity = Binder.clearCallingIdentity(); |
| 3255 | try { |
| 3256 | final Phone phone = getPhone(subId); |
| 3257 | if (phone != null) { |
| 3258 | phone.setVoiceActivationState(activationState); |
| 3259 | } else { |
| 3260 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3261 | } |
| 3262 | } finally { |
| 3263 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | /** |
| 3268 | * Sets the data activation state of a given subId. |
| 3269 | */ |
| 3270 | @Override |
| 3271 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3272 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3273 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | |
| 3275 | final long identity = Binder.clearCallingIdentity(); |
| 3276 | try { |
| 3277 | final Phone phone = getPhone(subId); |
| 3278 | if (phone != null) { |
| 3279 | phone.setDataActivationState(activationState); |
| 3280 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3281 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 | } |
| 3283 | } finally { |
| 3284 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | /** |
| 3289 | * Returns the voice activation state of a given subId. |
| 3290 | */ |
| 3291 | @Override |
| 3292 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3293 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3294 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3295 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3296 | final long identity = Binder.clearCallingIdentity(); |
| 3297 | try { |
| 3298 | if (phone != null) { |
| 3299 | return phone.getVoiceActivationState(); |
| 3300 | } else { |
| 3301 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3302 | } |
| 3303 | } finally { |
| 3304 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | /** |
| 3309 | * Returns the data activation state of a given subId. |
| 3310 | */ |
| 3311 | @Override |
| 3312 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3313 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3315 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3316 | final long identity = Binder.clearCallingIdentity(); |
| 3317 | try { |
| 3318 | if (phone != null) { |
| 3319 | return phone.getDataActivationState(); |
| 3320 | } else { |
| 3321 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3322 | } |
| 3323 | } finally { |
| 3324 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3329 | * Returns the unread count of voicemails for a subId |
| 3330 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3331 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3332 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3333 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3334 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3335 | mApp, subId, callingPackage, callingFeatureId, |
| 3336 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3337 | return 0; |
| 3338 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3339 | final long identity = Binder.clearCallingIdentity(); |
| 3340 | try { |
| 3341 | final Phone phone = getPhone(subId); |
| 3342 | if (phone != null) { |
| 3343 | return phone.getVoiceMessageCount(); |
| 3344 | } else { |
| 3345 | return 0; |
| 3346 | } |
| 3347 | } finally { |
| 3348 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3349 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3353 | * returns true, if the device is in a state where both voice and data |
| 3354 | * are supported simultaneously. This can change based on location or network condition. |
| 3355 | */ |
| 3356 | @Override |
| 3357 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | final long identity = Binder.clearCallingIdentity(); |
| 3359 | try { |
| 3360 | final Phone phone = getPhone(subId); |
| 3361 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3362 | } finally { |
| 3363 | Binder.restoreCallingIdentity(identity); |
| 3364 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3368 | * Send the dialer code if called from the current default dialer or the caller has |
| 3369 | * carrier privilege. |
| 3370 | * @param inputCode The dialer code to send |
| 3371 | */ |
| 3372 | @Override |
| 3373 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3374 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3375 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3376 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3377 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3378 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3379 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3380 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3381 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3382 | |
| 3383 | final long identity = Binder.clearCallingIdentity(); |
| 3384 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3385 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | } finally { |
| 3387 | Binder.restoreCallingIdentity(identity); |
| 3388 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3389 | } |
| 3390 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3391 | @Override |
| 3392 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3393 | TelephonyPermissions |
| 3394 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3395 | mApp, subId, "getNetworkSelectionMode"); |
| 3396 | final long identity = Binder.clearCallingIdentity(); |
| 3397 | try { |
| 3398 | if (!isActiveSubscription(subId)) { |
| 3399 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3400 | } |
| 3401 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3402 | } finally { |
| 3403 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3404 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3405 | } |
| 3406 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3407 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3408 | public boolean isInEmergencySmsMode() { |
| 3409 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3410 | final long identity = Binder.clearCallingIdentity(); |
| 3411 | try { |
| 3412 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3413 | if (phone.isInEmergencySmsMode()) { |
| 3414 | return true; |
| 3415 | } |
| 3416 | } |
| 3417 | } finally { |
| 3418 | Binder.restoreCallingIdentity(identity); |
| 3419 | } |
| 3420 | return false; |
| 3421 | } |
| 3422 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3423 | /** |
| 3424 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3425 | * @param subId The subscription to use to check the configuration. |
| 3426 | * @param c The callback that will be used to send the result. |
| 3427 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3428 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3429 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3430 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3431 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3432 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3433 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3434 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3435 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3436 | "IMS not available on device."); |
| 3437 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3438 | final long token = Binder.clearCallingIdentity(); |
| 3439 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3440 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3441 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3442 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3443 | } catch (ImsException e) { |
| 3444 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3445 | } finally { |
| 3446 | Binder.restoreCallingIdentity(token); |
| 3447 | } |
| 3448 | } |
| 3449 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3450 | /** |
| 3451 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3452 | * @param subId The subscription to use to check the configuration. |
| 3453 | * @param c The callback that will be used to send the result. |
| 3454 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3455 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3456 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3457 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3458 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3459 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3460 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3461 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3462 | final long token = Binder.clearCallingIdentity(); |
| 3463 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3464 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3465 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3466 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3467 | } catch (ImsException e) { |
| 3468 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3469 | + "is inactive, ignoring unregister."); |
| 3470 | // If the subscription is no longer active, just return, since the callback |
| 3471 | // will already have been removed internally. |
| 3472 | } finally { |
| 3473 | Binder.restoreCallingIdentity(token); |
| 3474 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3475 | } |
| 3476 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3477 | /** |
| 3478 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3479 | */ |
| 3480 | @Override |
| 3481 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3482 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3483 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3484 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3485 | "IMS not available on device."); |
| 3486 | } |
| 3487 | final long token = Binder.clearCallingIdentity(); |
| 3488 | try { |
| 3489 | Phone phone = getPhone(subId); |
| 3490 | if (phone == null) { |
| 3491 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3492 | + subId + "'"); |
| 3493 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3494 | } |
| 3495 | phone.getImsRegistrationState(regState -> { |
| 3496 | try { |
| 3497 | consumer.accept((regState == null) |
| 3498 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3499 | } catch (RemoteException e) { |
| 3500 | // Ignore if the remote process is no longer available to call back. |
| 3501 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3502 | } |
| 3503 | }); |
| 3504 | } finally { |
| 3505 | Binder.restoreCallingIdentity(token); |
| 3506 | } |
| 3507 | } |
| 3508 | |
| 3509 | /** |
| 3510 | * Get the transport type for the IMS service registration state. |
| 3511 | */ |
| 3512 | @Override |
| 3513 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3514 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3515 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3516 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3517 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3518 | "IMS not available on device."); |
| 3519 | } |
| 3520 | final long token = Binder.clearCallingIdentity(); |
| 3521 | try { |
| 3522 | Phone phone = getPhone(subId); |
| 3523 | if (phone == null) { |
| 3524 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3525 | + subId + "'"); |
| 3526 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3527 | } |
| 3528 | phone.getImsRegistrationTech(regTech -> { |
| 3529 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3530 | int regTechConverted = (regTech == null) |
| 3531 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3532 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3533 | regTechConverted); |
| 3534 | try { |
| 3535 | consumer.accept(regTechConverted); |
| 3536 | } catch (RemoteException e) { |
| 3537 | // Ignore if the remote process is no longer available to call back. |
| 3538 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3539 | } |
| 3540 | }); |
| 3541 | } finally { |
| 3542 | Binder.restoreCallingIdentity(token); |
| 3543 | } |
| 3544 | } |
| 3545 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3546 | /** |
| 3547 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3548 | * @param subId The subscription to use to check the configuration. |
| 3549 | * @param c The callback that will be used to send the result. |
| 3550 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3551 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3552 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3553 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3554 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3555 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3556 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3557 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3558 | "IMS not available on device."); |
| 3559 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3560 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3561 | final long token = Binder.clearCallingIdentity(); |
| 3562 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3563 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3564 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3565 | } catch (ImsException e) { |
| 3566 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3567 | } finally { |
| 3568 | Binder.restoreCallingIdentity(token); |
| 3569 | } |
| 3570 | } |
| 3571 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3572 | /** |
| 3573 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3574 | * @param subId The subscription to use to check the configuration. |
| 3575 | * @param c The callback that will be used to send the result. |
| 3576 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3577 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3578 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3579 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3580 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3581 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3582 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3583 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3584 | |
| 3585 | final long token = Binder.clearCallingIdentity(); |
| 3586 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3587 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3588 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3589 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3590 | } catch (ImsException e) { |
| 3591 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3592 | + "is inactive, ignoring unregister."); |
| 3593 | // If the subscription is no longer active, just return, since the callback |
| 3594 | // will already have been removed internally. |
| 3595 | } finally { |
| 3596 | Binder.restoreCallingIdentity(token); |
| 3597 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3601 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3602 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3603 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3604 | final long token = Binder.clearCallingIdentity(); |
| 3605 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3606 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3607 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3608 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3609 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3610 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3611 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3612 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3613 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3614 | } finally { |
| 3615 | Binder.restoreCallingIdentity(token); |
| 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3620 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3621 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3622 | final long token = Binder.clearCallingIdentity(); |
| 3623 | try { |
| 3624 | Phone phone = getPhone(subId); |
| 3625 | if (phone == null) return false; |
| 3626 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3627 | } catch (com.android.ims.ImsException e) { |
| 3628 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3629 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3630 | } finally { |
| 3631 | Binder.restoreCallingIdentity(token); |
| 3632 | } |
| 3633 | } |
| 3634 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3635 | /** |
| 3636 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3637 | * subscription. |
| 3638 | * @param subId The subscription to use to check the configuration. |
| 3639 | * @param callback The callback that will be used to send the result. |
| 3640 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3641 | * @param transportType The transport type of the MmTelFeature capability. |
| 3642 | */ |
| 3643 | @Override |
| 3644 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3645 | int transportType) { |
| 3646 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3647 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3648 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3649 | "IMS not available on device."); |
| 3650 | } |
| 3651 | final long token = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | int slotId = getSlotIndex(subId); |
| 3654 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3655 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3656 | + subId + "'"); |
| 3657 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3658 | } |
| 3659 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3660 | transportType, aBoolean -> { |
| 3661 | try { |
| 3662 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3663 | } catch (RemoteException e) { |
| 3664 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3665 | + "running. Ignore"); |
| 3666 | } |
| 3667 | }); |
| 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(token); |
| 3670 | } |
| 3671 | } |
| 3672 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3673 | /** |
| 3674 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3675 | * @param subId The subscription to use to check the configuration. |
| 3676 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3677 | @Override |
| 3678 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3679 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3680 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3681 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3682 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3683 | final long token = Binder.clearCallingIdentity(); |
| 3684 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3685 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3686 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3687 | } catch (ImsException e) { |
| 3688 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(token); |
| 3691 | } |
| 3692 | } |
| 3693 | |
| 3694 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3695 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3696 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3697 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3701 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3702 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3703 | } catch (ImsException e) { |
| 3704 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3705 | } finally { |
| 3706 | Binder.restoreCallingIdentity(identity); |
| 3707 | } |
| 3708 | } |
| 3709 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3710 | /** |
| 3711 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3712 | * @param subId The subscription to use to check the configuration. |
| 3713 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3714 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3715 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3716 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3717 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3718 | final long identity = Binder.clearCallingIdentity(); |
| 3719 | try { |
| 3720 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3721 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3722 | } catch (ImsException e) { |
| 3723 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3724 | } finally { |
| 3725 | Binder.restoreCallingIdentity(identity); |
| 3726 | } |
| 3727 | } |
| 3728 | |
| 3729 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3730 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3731 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3732 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3733 | final long identity = Binder.clearCallingIdentity(); |
| 3734 | try { |
| 3735 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3736 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3737 | } catch (ImsException e) { |
| 3738 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3739 | } finally { |
| 3740 | Binder.restoreCallingIdentity(identity); |
| 3741 | } |
| 3742 | } |
| 3743 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3744 | /** |
| 3745 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3746 | * @param subId The subscription to use to check the configuration. |
| 3747 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3748 | @Override |
| 3749 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3750 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3751 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3752 | final long identity = Binder.clearCallingIdentity(); |
| 3753 | try { |
| 3754 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3755 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3756 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3757 | } catch (ImsException e) { |
| 3758 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3759 | } finally { |
| 3760 | Binder.restoreCallingIdentity(identity); |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3765 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3767 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3768 | final long identity = Binder.clearCallingIdentity(); |
| 3769 | try { |
| 3770 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3771 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3772 | } catch (ImsException e) { |
| 3773 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3774 | } finally { |
| 3775 | Binder.restoreCallingIdentity(identity); |
| 3776 | } |
| 3777 | } |
| 3778 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3779 | /** |
| 3780 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3781 | * @param subId The subscription to use to check the configuration. |
| 3782 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3783 | @Override |
| 3784 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3785 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3786 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3787 | final long identity = Binder.clearCallingIdentity(); |
| 3788 | try { |
| 3789 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3790 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3791 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3792 | } catch (ImsException e) { |
| 3793 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3794 | } finally { |
| 3795 | Binder.restoreCallingIdentity(identity); |
| 3796 | } |
| 3797 | } |
| 3798 | |
| 3799 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3800 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3801 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3802 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3803 | final long identity = Binder.clearCallingIdentity(); |
| 3804 | try { |
| 3805 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3806 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3807 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3808 | } catch (ImsException e) { |
| 3809 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3810 | } finally { |
| 3811 | Binder.restoreCallingIdentity(identity); |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | @Override |
| 3816 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3817 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3818 | "setVoWiFiNonPersistent"); |
| 3819 | final long identity = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3822 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3823 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3824 | } catch (ImsException e) { |
| 3825 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3826 | } finally { |
| 3827 | Binder.restoreCallingIdentity(identity); |
| 3828 | } |
| 3829 | } |
| 3830 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3831 | /** |
| 3832 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3833 | * @param subId The subscription to use to check the configuration. |
| 3834 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3835 | @Override |
| 3836 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3837 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3838 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3839 | final long identity = Binder.clearCallingIdentity(); |
| 3840 | try { |
| 3841 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3842 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3843 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3844 | } catch (ImsException e) { |
| 3845 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3846 | } finally { |
| 3847 | Binder.restoreCallingIdentity(identity); |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | @Override |
| 3852 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3853 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3854 | "setVoWiFiModeSetting"); |
| 3855 | final long identity = Binder.clearCallingIdentity(); |
| 3856 | try { |
| 3857 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3858 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3859 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3860 | } catch (ImsException e) { |
| 3861 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | @Override |
| 3868 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3869 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3870 | final long identity = Binder.clearCallingIdentity(); |
| 3871 | try { |
| 3872 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3873 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3874 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3875 | } catch (ImsException e) { |
| 3876 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3877 | } finally { |
| 3878 | Binder.restoreCallingIdentity(identity); |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | @Override |
| 3883 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3884 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3885 | "setVoWiFiRoamingModeSetting"); |
| 3886 | final long identity = Binder.clearCallingIdentity(); |
| 3887 | try { |
| 3888 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3889 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3890 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3891 | } catch (ImsException e) { |
| 3892 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3893 | } finally { |
| 3894 | Binder.restoreCallingIdentity(identity); |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | @Override |
| 3899 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3900 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3901 | "setRttCapabilityEnabled"); |
| 3902 | final long identity = Binder.clearCallingIdentity(); |
| 3903 | try { |
| 3904 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3905 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3906 | } catch (ImsException e) { |
| 3907 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3908 | } finally { |
| 3909 | Binder.restoreCallingIdentity(identity); |
| 3910 | } |
| 3911 | } |
| 3912 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3913 | /** |
| 3914 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3915 | * @param subId The subscription to use to check the configuration. |
| 3916 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3917 | @Override |
| 3918 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3919 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3920 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3921 | final long identity = Binder.clearCallingIdentity(); |
| 3922 | try { |
| 3923 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3924 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3925 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3926 | } catch (ImsException e) { |
| 3927 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3928 | } finally { |
| 3929 | Binder.restoreCallingIdentity(identity); |
| 3930 | } |
| 3931 | } |
| 3932 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3933 | @Override |
| 3934 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3935 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3936 | final long identity = Binder.clearCallingIdentity(); |
| 3937 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3938 | if (!isImsAvailableOnDevice()) { |
| 3939 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3940 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3941 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3942 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3943 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3944 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3945 | } catch (ImsException e) { |
| 3946 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3947 | } finally { |
| 3948 | Binder.restoreCallingIdentity(identity); |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | @Override |
| 3953 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3954 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3955 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3956 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3957 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3958 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3959 | try { |
| 3960 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3961 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3962 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3963 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3964 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3965 | + "is inactive, ignoring unregister."); |
| 3966 | // If the subscription is no longer active, just return, since the callback will already |
| 3967 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3968 | } finally { |
| 3969 | Binder.restoreCallingIdentity(identity); |
| 3970 | } |
| 3971 | } |
| 3972 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3973 | |
| 3974 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3976 | message); |
| 3977 | } |
| 3978 | |
| 3979 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3980 | boolean isMmtelCapability) { |
| 3981 | Phone phone = getPhone(subId); |
| 3982 | if (phone == null) { |
| 3983 | loge("phone instance null for subid " + subId); |
| 3984 | return false; |
| 3985 | } |
| 3986 | if (isMmtelCapability) { |
| 3987 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3988 | return false; |
| 3989 | } |
| 3990 | } else { |
| 3991 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3992 | return false; |
| 3993 | } |
| 3994 | } |
| 3995 | return true; |
| 3996 | } |
| 3997 | |
| 3998 | @Override |
| 3999 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4000 | boolean isProvisioned) { |
| 4001 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4002 | |
| 4003 | final long identity = Binder.clearCallingIdentity(); |
| 4004 | try { |
| 4005 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4006 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4007 | return; |
| 4008 | } |
| 4009 | |
| 4010 | // this capability requires provisioning, route to the correct API. |
| 4011 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4012 | switch (capability) { |
| 4013 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4014 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4015 | ims.setEabProvisioned(isProvisioned); |
| 4016 | break; |
| 4017 | default: { |
| 4018 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4019 | + "rcs capability '" + capability + "', which does not require " |
| 4020 | + "provisioning."); |
| 4021 | } |
| 4022 | } |
| 4023 | } finally { |
| 4024 | Binder.restoreCallingIdentity(identity); |
| 4025 | } |
| 4026 | |
| 4027 | } |
| 4028 | |
| 4029 | |
| 4030 | @Override |
| 4031 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4032 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4033 | final long identity = Binder.clearCallingIdentity(); |
| 4034 | try { |
| 4035 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4036 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4037 | return true; |
| 4038 | } |
| 4039 | |
| 4040 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4041 | switch (capability) { |
| 4042 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4043 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4044 | return ims.isEabProvisionedOnDevice(); |
| 4045 | |
| 4046 | default: { |
| 4047 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4048 | + "capability '" + capability + "', which does not require " |
| 4049 | + "provisioning."); |
| 4050 | } |
| 4051 | } |
| 4052 | |
| 4053 | } finally { |
| 4054 | Binder.restoreCallingIdentity(identity); |
| 4055 | } |
| 4056 | } |
| 4057 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4058 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4059 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4060 | boolean isProvisioned) { |
| 4061 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4062 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4063 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4064 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4065 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4066 | final long identity = Binder.clearCallingIdentity(); |
| 4067 | try { |
| 4068 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4069 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4070 | return; |
| 4071 | } |
| 4072 | |
| 4073 | // this capability requires provisioning, route to the correct API. |
| 4074 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4075 | switch (capability) { |
| 4076 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4077 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4078 | ims.setVolteProvisioned(isProvisioned); |
| 4079 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4080 | ims.setWfcProvisioned(isProvisioned); |
| 4081 | } |
| 4082 | break; |
| 4083 | } |
| 4084 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4085 | // There is currently no difference in VT provisioning type. |
| 4086 | ims.setVtProvisioned(isProvisioned); |
| 4087 | break; |
| 4088 | } |
| 4089 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4090 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4091 | // change the capability of the feature instead if needed. |
| 4092 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4093 | == isProvisioned) { |
| 4094 | // No change in provisioning. |
| 4095 | return; |
| 4096 | } |
| 4097 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4098 | try { |
| 4099 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4100 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4101 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4102 | + ", Exception" + e.getMessage()); |
| 4103 | } |
| 4104 | break; |
| 4105 | } |
| 4106 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4107 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4108 | + "MmTel capability '" + capability + "', which does not require " |
| 4109 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | @Override |
| 4119 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4120 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4121 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4122 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4123 | } |
| 4124 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4128 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4129 | return true; |
| 4130 | } |
| 4131 | |
| 4132 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4133 | switch (capability) { |
| 4134 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4135 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4136 | return ims.isVolteProvisionedOnDevice(); |
| 4137 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4138 | return ims.isWfcProvisionedOnDevice(); |
| 4139 | } |
| 4140 | // This should never happen, since we are checking tech above to make sure it |
| 4141 | // is either LTE or IWLAN. |
| 4142 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4143 | + "capability."); |
| 4144 | } |
| 4145 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4146 | // There is currently no difference in VT provisioning type. |
| 4147 | return ims.isVtProvisionedOnDevice(); |
| 4148 | } |
| 4149 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4150 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4151 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4152 | } |
| 4153 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4154 | throw new IllegalArgumentException( |
| 4155 | "Tried to get provisioning for MmTel capability '" + capability |
| 4156 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | } finally { |
| 4161 | Binder.restoreCallingIdentity(identity); |
| 4162 | } |
| 4163 | } |
| 4164 | |
| 4165 | @Override |
| 4166 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4167 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4168 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4169 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4170 | } |
| 4171 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4172 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4173 | return (provisionedBits & capability) > 0; |
| 4174 | } |
| 4175 | |
| 4176 | @Override |
| 4177 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4178 | boolean isProvisioned) { |
| 4179 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4180 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4181 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4182 | } |
| 4183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4184 | "setProvisioningStatusForCapability"); |
| 4185 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4186 | // If the current provisioning status for capability already matches isProvisioned, |
| 4187 | // do nothing. |
| 4188 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4189 | return; |
| 4190 | } |
| 4191 | if (isProvisioned) { |
| 4192 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4193 | } else { |
| 4194 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | /** |
| 4199 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4200 | * technology. The bitfield should mirror the bitfield defined by |
| 4201 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4202 | */ |
| 4203 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4204 | String key = getMmTelProvisioningKey(subId, tech); |
| 4205 | // Default is no capabilities are provisioned. |
| 4206 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4207 | } |
| 4208 | |
| 4209 | /** |
| 4210 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4211 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4212 | * technology specified. |
| 4213 | * |
| 4214 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4215 | */ |
| 4216 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4217 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4218 | String key = getMmTelProvisioningKey(subId, tech); |
| 4219 | editor.putInt(key, newField); |
| 4220 | editor.commit(); |
| 4221 | } |
| 4222 | |
| 4223 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4224 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4225 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4226 | } |
| 4227 | |
| 4228 | /** |
| 4229 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4230 | * carrier associated with the subscription id. |
| 4231 | */ |
| 4232 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4233 | int capability) { |
| 4234 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4235 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4236 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4237 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4238 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4239 | false); |
| 4240 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4241 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4242 | |
| 4243 | // First check to make sure that the capability requires provisioning. |
| 4244 | switch (capability) { |
| 4245 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4246 | // intentional fallthrough |
| 4247 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4248 | if (requireVoiceVtProvisioning) { |
| 4249 | // Voice and Video requires provisioning |
| 4250 | return true; |
| 4251 | } |
| 4252 | break; |
| 4253 | } |
| 4254 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4255 | if (requireUtProvisioning) { |
| 4256 | // UT requires provisioning |
| 4257 | return true; |
| 4258 | } |
| 4259 | break; |
| 4260 | } |
| 4261 | } |
| 4262 | return false; |
| 4263 | } |
| 4264 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4265 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4266 | int capability) { |
| 4267 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4268 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4269 | |
| 4270 | boolean requireRcsProvisioning = c.getBoolean( |
| 4271 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4272 | |
| 4273 | // First check to make sure that the capability requires provisioning. |
| 4274 | switch (capability) { |
| 4275 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4276 | // intentional fallthrough |
| 4277 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4278 | if (requireRcsProvisioning) { |
| 4279 | // OPTION or PRESENCE requires provisioning |
| 4280 | return true; |
| 4281 | } |
| 4282 | break; |
| 4283 | } |
| 4284 | } |
| 4285 | return false; |
| 4286 | } |
| 4287 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4288 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4289 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4290 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4291 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4292 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4293 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4294 | final long identity = Binder.clearCallingIdentity(); |
| 4295 | try { |
| 4296 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4297 | int slotId = getSlotIndex(subId); |
| 4298 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4299 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4300 | + subId + "' for key:" + key); |
| 4301 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4302 | } |
| 4303 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4304 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4305 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4306 | + subId + "' for key:" + key); |
| 4307 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4308 | } finally { |
| 4309 | Binder.restoreCallingIdentity(identity); |
| 4310 | } |
| 4311 | } |
| 4312 | |
| 4313 | @Override |
| 4314 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4315 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4316 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4317 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4318 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4319 | final long identity = Binder.clearCallingIdentity(); |
| 4320 | try { |
| 4321 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4322 | int slotId = getSlotIndex(subId); |
| 4323 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4324 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4325 | + subId + "' for key:" + key); |
| 4326 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4327 | } |
| 4328 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4329 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4330 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4331 | + subId + "' for key:" + key); |
| 4332 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4333 | } finally { |
| 4334 | Binder.restoreCallingIdentity(identity); |
| 4335 | } |
| 4336 | } |
| 4337 | |
| 4338 | @Override |
| 4339 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4340 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4341 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4342 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4343 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4344 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4345 | final long identity = Binder.clearCallingIdentity(); |
| 4346 | try { |
| 4347 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4348 | int slotId = getSlotIndex(subId); |
| 4349 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4350 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4351 | + subId + "' for key:" + key); |
| 4352 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4353 | } |
| 4354 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4355 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4356 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4357 | + "' for key:" + key); |
| 4358 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4359 | } finally { |
| 4360 | Binder.restoreCallingIdentity(identity); |
| 4361 | } |
| 4362 | } |
| 4363 | |
| 4364 | @Override |
| 4365 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4366 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4367 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4368 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4370 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4371 | final long identity = Binder.clearCallingIdentity(); |
| 4372 | try { |
| 4373 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4374 | int slotId = getSlotIndex(subId); |
| 4375 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4376 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4377 | + subId + "' for key:" + key); |
| 4378 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4379 | } |
| 4380 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4381 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4382 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4383 | + "' for key:" + key); |
| 4384 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4385 | } finally { |
| 4386 | Binder.restoreCallingIdentity(identity); |
| 4387 | } |
| 4388 | } |
| 4389 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4390 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4391 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4392 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4393 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4394 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4395 | } |
| 4396 | return slotId; |
| 4397 | } |
| 4398 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4399 | private int getSlotIndex(int subId) { |
| 4400 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4401 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4402 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4403 | } |
| 4404 | return slotId; |
| 4405 | } |
| 4406 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4407 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4408 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4409 | */ |
| 4410 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4411 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4412 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4413 | final int targetSdk = getTargetSdk(callingPackage); |
| 4414 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4415 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4416 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4417 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4418 | mApp, subId, callingPackage, callingFeatureId, |
| 4419 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4420 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4421 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4423 | final long identity = Binder.clearCallingIdentity(); |
| 4424 | try { |
| 4425 | final Phone phone = getPhone(subId); |
| 4426 | if (phone != null) { |
| 4427 | return phone.getServiceState().getDataNetworkType(); |
| 4428 | } else { |
| 4429 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4430 | } |
| 4431 | } finally { |
| 4432 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4433 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4434 | } |
| 4435 | |
| 4436 | /** |
| 4437 | * Returns the data network type |
| 4438 | */ |
| 4439 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4440 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4441 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4442 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4443 | } |
| 4444 | |
| 4445 | /** |
| 4446 | * Returns the data network type for a subId |
| 4447 | */ |
| 4448 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4449 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4450 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4451 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4452 | mApp, subId, callingPackage, callingFeatureId, |
| 4453 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4454 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4455 | } |
| 4456 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4457 | final long identity = Binder.clearCallingIdentity(); |
| 4458 | try { |
| 4459 | final Phone phone = getPhone(subId); |
| 4460 | if (phone != null) { |
| 4461 | return phone.getServiceState().getDataNetworkType(); |
| 4462 | } else { |
| 4463 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4464 | } |
| 4465 | } finally { |
| 4466 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4467 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4471 | * Returns the Voice network type for a subId |
| 4472 | */ |
| 4473 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4474 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4475 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4476 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4477 | mApp, subId, callingPackage, callingFeatureId, |
| 4478 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4479 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4480 | } |
| 4481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | final long identity = Binder.clearCallingIdentity(); |
| 4483 | try { |
| 4484 | final Phone phone = getPhone(subId); |
| 4485 | if (phone != null) { |
| 4486 | return phone.getServiceState().getVoiceNetworkType(); |
| 4487 | } else { |
| 4488 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4489 | } |
| 4490 | } finally { |
| 4491 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4492 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | /** |
| 4496 | * @return true if a ICC card is present |
| 4497 | */ |
| 4498 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4499 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4500 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4501 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4505 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4506 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4507 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4508 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4509 | final long identity = Binder.clearCallingIdentity(); |
| 4510 | try { |
| 4511 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4512 | if (phone != null) { |
| 4513 | return phone.getIccCard().hasIccCard(); |
| 4514 | } else { |
| 4515 | return false; |
| 4516 | } |
| 4517 | } finally { |
| 4518 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | /** |
| 4523 | * Return if the current radio is LTE on CDMA. This |
| 4524 | * is a tri-state return value as for a period of time |
| 4525 | * the mode may be unknown. |
| 4526 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4527 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4528 | * @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] | 4529 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4530 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4531 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4532 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4533 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4534 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4535 | } |
| 4536 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4537 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4538 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4539 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4540 | try { |
| 4541 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4542 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4543 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4544 | } |
| 4545 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4546 | final long identity = Binder.clearCallingIdentity(); |
| 4547 | try { |
| 4548 | final Phone phone = getPhone(subId); |
| 4549 | if (phone == null) { |
| 4550 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4551 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4552 | return TelephonyProperties.lte_on_cdma_device() |
| 4553 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4554 | } |
| 4555 | } finally { |
| 4556 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4557 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4560 | /** |
| 4561 | * {@hide} |
| 4562 | * Returns Default subId, 0 in the case of single standby. |
| 4563 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4564 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4565 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4566 | } |
| 4567 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4568 | private int getSlotForDefaultSubscription() { |
| 4569 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4570 | } |
| 4571 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4572 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4573 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4574 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4575 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4576 | private boolean isActiveSubscription(int subId) { |
| 4577 | return mSubscriptionController.isActiveSubId(subId); |
| 4578 | } |
| 4579 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4580 | /** |
| 4581 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4582 | */ |
| 4583 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4584 | final long identity = Binder.clearCallingIdentity(); |
| 4585 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4586 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4587 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4588 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4589 | } finally { |
| 4590 | Binder.restoreCallingIdentity(identity); |
| 4591 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | /** |
| 4595 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4596 | */ |
| 4597 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4598 | final long identity = Binder.clearCallingIdentity(); |
| 4599 | try { |
| 4600 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4601 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4602 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4603 | } finally { |
| 4604 | Binder.restoreCallingIdentity(identity); |
| 4605 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4606 | } |
| 4607 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4608 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4609 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4610 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4611 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4612 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4613 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4614 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4615 | if (phoneId == -1) { |
| 4616 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4617 | + " does not correspond to an active phone"); |
| 4618 | } |
| 4619 | return PhoneFactory.getPhone(phoneId); |
| 4620 | } |
| 4621 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4622 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4623 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4624 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4626 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4627 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4628 | if (DBG) { |
| 4629 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4630 | } |
| 4631 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4632 | p2); |
| 4633 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4634 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4635 | |
| 4636 | @Override |
| 4637 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4638 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4639 | enforceModifyPermission(); |
| 4640 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4641 | if (DBG) { |
| 4642 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4643 | } |
| 4644 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4645 | callingPackage, aid, p2); |
| 4646 | } |
| 4647 | |
| 4648 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4649 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4650 | final long identity = Binder.clearCallingIdentity(); |
| 4651 | try { |
| 4652 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4653 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4654 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4655 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4656 | if (bestComponent == null |
| 4657 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4658 | loge("The calling package is not allowed to access ISD-R."); |
| 4659 | throw new SecurityException( |
| 4660 | "The calling package is not allowed to access ISD-R."); |
| 4661 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4662 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4663 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4664 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4665 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4666 | null /* workSource */); |
| 4667 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4668 | return response; |
| 4669 | } finally { |
| 4670 | Binder.restoreCallingIdentity(identity); |
| 4671 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4675 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4676 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4677 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4678 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4679 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4680 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4681 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4682 | @Override |
| 4683 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4684 | enforceModifyPermission(); |
| 4685 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4686 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4687 | channel); |
| 4688 | } |
| 4689 | |
| 4690 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | final long identity = Binder.clearCallingIdentity(); |
| 4692 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4693 | if (channel < 0) { |
| 4694 | return false; |
| 4695 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4696 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4697 | null /* workSource */); |
| 4698 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4699 | return success; |
| 4700 | } finally { |
| 4701 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4702 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4706 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4707 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4708 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4709 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4710 | if (DBG) { |
| 4711 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4712 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4713 | + p3 + " data=" + data); |
| 4714 | } |
| 4715 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4716 | command, p1, p2, p3, data); |
| 4717 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4718 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4719 | @Override |
| 4720 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4721 | int command, int p1, int p2, int p3, String data) { |
| 4722 | enforceModifyPermission(); |
| 4723 | if (DBG) { |
| 4724 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4725 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4726 | + p3 + " data=" + data); |
| 4727 | } |
| 4728 | return iccTransmitApduLogicalChannelWithPermission( |
| 4729 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4730 | data); |
| 4731 | } |
| 4732 | |
| 4733 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4734 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 | final long identity = Binder.clearCallingIdentity(); |
| 4736 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4737 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4738 | return ""; |
| 4739 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4740 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4741 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4742 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4743 | null /* workSource */); |
| 4744 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4746 | // Append the returned status code to the end of the response payload. |
| 4747 | String s = Integer.toHexString( |
| 4748 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4749 | if (response.payload != null) { |
| 4750 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4751 | } |
| 4752 | return s; |
| 4753 | } finally { |
| 4754 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4755 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4756 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4757 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4758 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4759 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4760 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4761 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4762 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4764 | if (DBG) { |
| 4765 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4766 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4767 | } |
| 4768 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4769 | cla, command, p1, p2, p3, data); |
| 4770 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4771 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4772 | @Override |
| 4773 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4774 | int command, int p1, int p2, int p3, String data) { |
| 4775 | enforceModifyPermission(); |
| 4776 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4777 | if (DBG) { |
| 4778 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4779 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4780 | + " data=" + data); |
| 4781 | } |
| 4782 | |
| 4783 | return iccTransmitApduBasicChannelWithPermission( |
| 4784 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4785 | p2, p3, data); |
| 4786 | } |
| 4787 | |
| 4788 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4789 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4790 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4791 | final long identity = Binder.clearCallingIdentity(); |
| 4792 | try { |
| 4793 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4794 | && TextUtils.equals(ISDR_AID, data)) { |
| 4795 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4796 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4797 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4798 | if (bestComponent == null |
| 4799 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4800 | loge("The calling package is not allowed to select ISD-R."); |
| 4801 | throw new SecurityException( |
| 4802 | "The calling package is not allowed to select ISD-R."); |
| 4803 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4804 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4805 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4806 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4807 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4808 | null /* workSource */); |
| 4809 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4810 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4811 | // Append the returned status code to the end of the response payload. |
| 4812 | String s = Integer.toHexString( |
| 4813 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4814 | if (response.payload != null) { |
| 4815 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4816 | } |
| 4817 | return s; |
| 4818 | } finally { |
| 4819 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4820 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4824 | 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] | 4825 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4826 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4827 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4828 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4829 | final long identity = Binder.clearCallingIdentity(); |
| 4830 | try { |
| 4831 | if (DBG) { |
| 4832 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4833 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4834 | } |
| 4835 | |
| 4836 | IccIoResult response = |
| 4837 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4838 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4839 | subId); |
| 4840 | |
| 4841 | if (DBG) { |
| 4842 | log("Exchange SIM_IO [R]" + response); |
| 4843 | } |
| 4844 | |
| 4845 | byte[] result = null; |
| 4846 | int length = 2; |
| 4847 | if (response.payload != null) { |
| 4848 | length = 2 + response.payload.length; |
| 4849 | result = new byte[length]; |
| 4850 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4851 | } else { |
| 4852 | result = new byte[length]; |
| 4853 | } |
| 4854 | |
| 4855 | result[length - 1] = (byte) response.sw2; |
| 4856 | result[length - 2] = (byte) response.sw1; |
| 4857 | return result; |
| 4858 | } finally { |
| 4859 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4860 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4861 | } |
| 4862 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4863 | /** |
| 4864 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4865 | * on a particular subscription |
| 4866 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4867 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4868 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4869 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4870 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4871 | return null; |
| 4872 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4873 | |
| 4874 | final long identity = Binder.clearCallingIdentity(); |
| 4875 | try { |
| 4876 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4877 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4878 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4879 | return null; |
| 4880 | } |
| 4881 | Object response = sendRequest( |
| 4882 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4883 | if (response instanceof String[]) { |
| 4884 | return (String[]) response; |
| 4885 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4886 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4887 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4888 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | } finally { |
| 4890 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4891 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4892 | } |
| 4893 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4894 | /** |
| 4895 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4896 | * subscription. |
| 4897 | * |
| 4898 | * @param subId the id of the subscription. |
| 4899 | * @param appType the uicc app type, must be USIM or SIM. |
| 4900 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4901 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4902 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4903 | * @return number of fplmns that is successfully written to the SIM. |
| 4904 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4905 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4906 | String callingFeatureId) { |
| 4907 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4908 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4909 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4910 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4911 | } |
| 4912 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4913 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4914 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4915 | } |
| 4916 | if (fplmns == null) { |
| 4917 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4918 | } |
| 4919 | for (String fplmn : fplmns) { |
| 4920 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4921 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4922 | } |
| 4923 | } |
| 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
| 4926 | Object response = sendRequest( |
| 4927 | CMD_SET_FORBIDDEN_PLMNS, |
| 4928 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4929 | subId); |
| 4930 | return (int) response; |
| 4931 | } finally { |
| 4932 | Binder.restoreCallingIdentity(identity); |
| 4933 | } |
| 4934 | } |
| 4935 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4936 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4937 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4938 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4939 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4940 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4941 | final long identity = Binder.clearCallingIdentity(); |
| 4942 | try { |
| 4943 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4944 | if (response.payload == null) { |
| 4945 | return ""; |
| 4946 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4947 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4948 | // Append the returned status code to the end of the response payload. |
| 4949 | String s = Integer.toHexString( |
| 4950 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4951 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4952 | return s; |
| 4953 | } finally { |
| 4954 | Binder.restoreCallingIdentity(identity); |
| 4955 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4956 | } |
| 4957 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4958 | /** |
| 4959 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4960 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4961 | * |
| 4962 | * @param itemID the ID of the item to read |
| 4963 | * @return the NV item as a String, or null on error. |
| 4964 | */ |
| 4965 | @Override |
| 4966 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4967 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4969 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | |
| 4971 | final long identity = Binder.clearCallingIdentity(); |
| 4972 | try { |
| 4973 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4974 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4976 | return value; |
| 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
| 4979 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | /** |
| 4983 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4984 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4985 | * |
| 4986 | * @param itemID the ID of the item to read |
| 4987 | * @param itemValue the value to write, as a String |
| 4988 | * @return true on success; false on any failure |
| 4989 | */ |
| 4990 | @Override |
| 4991 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4992 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4994 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4995 | |
| 4996 | final long identity = Binder.clearCallingIdentity(); |
| 4997 | try { |
| 4998 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4999 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5000 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5002 | return success; |
| 5003 | } finally { |
| 5004 | Binder.restoreCallingIdentity(identity); |
| 5005 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | /** |
| 5009 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5010 | * Used for device configuration by some CDMA operators. |
| 5011 | * |
| 5012 | * @param preferredRoamingList byte array containing the new PRL |
| 5013 | * @return true on success; false on any failure |
| 5014 | */ |
| 5015 | @Override |
| 5016 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5018 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5019 | |
| 5020 | final long identity = Binder.clearCallingIdentity(); |
| 5021 | try { |
| 5022 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5023 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5024 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5025 | return success; |
| 5026 | } finally { |
| 5027 | Binder.restoreCallingIdentity(identity); |
| 5028 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5032 | * 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] | 5033 | * Used for device configuration by some CDMA operators. |
| 5034 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5035 | * @param slotIndex - device slot. |
| 5036 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5037 | * @return true on success; false on any failure |
| 5038 | */ |
| 5039 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5040 | public boolean resetModemConfig(int slotIndex) { |
| 5041 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5042 | if (phone != null) { |
| 5043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5044 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5045 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5046 | final long identity = Binder.clearCallingIdentity(); |
| 5047 | try { |
| 5048 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5049 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5050 | return success; |
| 5051 | } finally { |
| 5052 | Binder.restoreCallingIdentity(identity); |
| 5053 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5055 | return false; |
| 5056 | } |
| 5057 | |
| 5058 | /** |
| 5059 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5060 | * |
| 5061 | * @param slotIndex - device slot. |
| 5062 | * |
| 5063 | * @return true on success; false on any failure |
| 5064 | */ |
| 5065 | @Override |
| 5066 | public boolean rebootModem(int slotIndex) { |
| 5067 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5068 | if (phone != null) { |
| 5069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5070 | mApp, phone.getSubId(), "rebootModem"); |
| 5071 | |
| 5072 | final long identity = Binder.clearCallingIdentity(); |
| 5073 | try { |
| 5074 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5075 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5076 | return success; |
| 5077 | } finally { |
| 5078 | Binder.restoreCallingIdentity(identity); |
| 5079 | } |
| 5080 | } |
| 5081 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5082 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5083 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5084 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5085 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5086 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5087 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5088 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5089 | return new String[0]; |
| 5090 | } |
| 5091 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5092 | final long identity = Binder.clearCallingIdentity(); |
| 5093 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5094 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 | } finally { |
| 5096 | Binder.restoreCallingIdentity(identity); |
| 5097 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5098 | } |
| 5099 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5100 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5101 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5102 | * {@link #disableIms(int)}. |
| 5103 | * @param slotIndex device slot. |
| 5104 | */ |
| 5105 | public void resetIms(int slotIndex) { |
| 5106 | enforceModifyPermission(); |
| 5107 | |
| 5108 | final long identity = Binder.clearCallingIdentity(); |
| 5109 | try { |
| 5110 | if (mImsResolver == null) { |
| 5111 | // may happen if the does not support IMS. |
| 5112 | return; |
| 5113 | } |
| 5114 | mImsResolver.disableIms(slotIndex); |
| 5115 | mImsResolver.enableIms(slotIndex); |
| 5116 | } finally { |
| 5117 | Binder.restoreCallingIdentity(identity); |
| 5118 | } |
| 5119 | } |
| 5120 | |
| 5121 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5122 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5123 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5124 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5125 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5126 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5127 | |
| 5128 | final long identity = Binder.clearCallingIdentity(); |
| 5129 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5130 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5131 | // may happen if the device does not support IMS. |
| 5132 | return; |
| 5133 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5134 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5135 | } finally { |
| 5136 | Binder.restoreCallingIdentity(identity); |
| 5137 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5141 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5142 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5143 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5144 | public void disableIms(int slotId) { |
| 5145 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5146 | |
| 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5149 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5150 | // may happen if the device does not support IMS. |
| 5151 | return; |
| 5152 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5153 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | } finally { |
| 5155 | Binder.restoreCallingIdentity(identity); |
| 5156 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5160 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5161 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5162 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5163 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5164 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5165 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5166 | |
| 5167 | final long identity = Binder.clearCallingIdentity(); |
| 5168 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5169 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5170 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5171 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5172 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5173 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
| 5176 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5177 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5178 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5179 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5180 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5181 | @Override |
| 5182 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5183 | enforceModifyPermission(); |
| 5184 | |
| 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
| 5187 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5188 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5189 | } finally { |
| 5190 | Binder.restoreCallingIdentity(identity); |
| 5191 | } |
| 5192 | } |
| 5193 | |
| 5194 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5195 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5196 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5197 | */ |
| 5198 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5199 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5200 | |
| 5201 | final long identity = Binder.clearCallingIdentity(); |
| 5202 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5203 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5204 | // may happen if the device does not support IMS. |
| 5205 | return null; |
| 5206 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5207 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | } finally { |
| 5209 | Binder.restoreCallingIdentity(identity); |
| 5210 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5211 | } |
| 5212 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5213 | /** |
| 5214 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5215 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5216 | */ |
| 5217 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5219 | |
| 5220 | final long identity = Binder.clearCallingIdentity(); |
| 5221 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5222 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5223 | // may happen if the device does not support IMS. |
| 5224 | return null; |
| 5225 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5226 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5227 | } finally { |
| 5228 | Binder.restoreCallingIdentity(identity); |
| 5229 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5230 | } |
| 5231 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5232 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5233 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5234 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5235 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5236 | * @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] | 5237 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5238 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5239 | * @param packageName The name of the package that the current configuration will be replaced |
| 5240 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5241 | * @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] | 5242 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5243 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5244 | int[] featureTypes, String packageName) { |
| 5245 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5246 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5248 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5249 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5250 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5253 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5254 | // may happen if the device does not support IMS. |
| 5255 | return false; |
| 5256 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5257 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5258 | for (int featureType : featureTypes) { |
| 5259 | featureConfig.put(featureType, packageName); |
| 5260 | } |
| 5261 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5262 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | } finally { |
| 5264 | Binder.restoreCallingIdentity(identity); |
| 5265 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5269 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5270 | * |
| 5271 | * @param slotId The slot that the ImsService is associated with. |
| 5272 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5273 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5274 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5275 | * @return the package name of the ImsService configuration. |
| 5276 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5277 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5278 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5279 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5280 | TelephonyPermissions |
| 5281 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5282 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5283 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5284 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | final long identity = Binder.clearCallingIdentity(); |
| 5286 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5287 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5288 | // may happen if the device does not support IMS. |
| 5289 | return ""; |
| 5290 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5291 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5292 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5293 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | } finally { |
| 5295 | Binder.restoreCallingIdentity(identity); |
| 5296 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5297 | } |
| 5298 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5299 | /** |
| 5300 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5301 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5302 | * @param callback A callback with an integer containing the |
| 5303 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5304 | */ |
| 5305 | @Override |
| 5306 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5307 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5308 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5309 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5310 | "IMS not available on device."); |
| 5311 | } |
| 5312 | final long token = Binder.clearCallingIdentity(); |
| 5313 | try { |
| 5314 | int slotId = getSlotIndex(subId); |
| 5315 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5316 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5317 | + subId + "'"); |
| 5318 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5319 | } |
| 5320 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5321 | try { |
| 5322 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5323 | } catch (RemoteException e) { |
| 5324 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5325 | + "Ignore"); |
| 5326 | } |
| 5327 | }); |
| 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(token); |
| 5330 | } |
| 5331 | } |
| 5332 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5333 | public void setImsRegistrationState(boolean registered) { |
| 5334 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5335 | |
| 5336 | final long identity = Binder.clearCallingIdentity(); |
| 5337 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5338 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | } finally { |
| 5340 | Binder.restoreCallingIdentity(identity); |
| 5341 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5345 | * Set the network selection mode to automatic. |
| 5346 | * |
| 5347 | */ |
| 5348 | @Override |
| 5349 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5350 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5351 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | |
| 5353 | final long identity = Binder.clearCallingIdentity(); |
| 5354 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5355 | if (!isActiveSubscription(subId)) { |
| 5356 | return; |
| 5357 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5359 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5360 | } finally { |
| 5361 | Binder.restoreCallingIdentity(identity); |
| 5362 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5363 | } |
| 5364 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5365 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5366 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5367 | * |
| 5368 | * @param subId the id of the subscription. |
| 5369 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5370 | * the operator to attach to. |
| 5371 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5372 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5373 | * normal network selection next time. |
| 5374 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5375 | */ |
| 5376 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5377 | public boolean setNetworkSelectionModeManual( |
| 5378 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5380 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5381 | |
| 5382 | if (!isActiveSubscription(subId)) { |
| 5383 | return false; |
| 5384 | } |
| 5385 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5386 | final long identity = Binder.clearCallingIdentity(); |
| 5387 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5388 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5389 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5390 | if (DBG) { |
| 5391 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5392 | + " operator: " + operatorInfo); |
| 5393 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5395 | } finally { |
| 5396 | Binder.restoreCallingIdentity(identity); |
| 5397 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5398 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5399 | /** |
| 5400 | * Get the manual network selection |
| 5401 | * |
| 5402 | * @param subId the id of the subscription. |
| 5403 | * |
| 5404 | * @return the previously saved user selected PLMN |
| 5405 | */ |
| 5406 | @Override |
| 5407 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5408 | TelephonyPermissions |
| 5409 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5410 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5411 | |
| 5412 | final long identity = Binder.clearCallingIdentity(); |
| 5413 | try { |
| 5414 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5415 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | final Phone phone = getPhone(subId); |
| 5419 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5420 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5421 | } |
| 5422 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5423 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5424 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5425 | } finally { |
| 5426 | Binder.restoreCallingIdentity(identity); |
| 5427 | } |
| 5428 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5429 | |
| 5430 | /** |
| 5431 | * Scans for available networks. |
| 5432 | */ |
| 5433 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5434 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5435 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5437 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5438 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5439 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5440 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5441 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5442 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5443 | .setCallingPid(Binder.getCallingPid()) |
| 5444 | .setCallingUid(Binder.getCallingUid()) |
| 5445 | .setMethod("getCellNetworkScanResults") |
| 5446 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5447 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5448 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5449 | .build()); |
| 5450 | switch (locationResult) { |
| 5451 | case DENIED_HARD: |
| 5452 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5453 | case DENIED_SOFT: |
| 5454 | return null; |
| 5455 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5456 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5457 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5458 | try { |
| 5459 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5460 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5461 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5462 | } finally { |
| 5463 | Binder.restoreCallingIdentity(identity); |
| 5464 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5468 | * Get the call forwarding info, given the call forwarding reason. |
| 5469 | */ |
| 5470 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5471 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5472 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5473 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5474 | long identity = Binder.clearCallingIdentity(); |
| 5475 | try { |
| 5476 | if (DBG) { |
| 5477 | log("getCallForwarding: subId " + subId |
| 5478 | + " callForwardingReason" + callForwardingReason); |
| 5479 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5480 | |
| 5481 | Phone phone = getPhone(subId); |
| 5482 | if (phone == null) { |
| 5483 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5484 | callback.onError( |
| 5485 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5486 | } catch (RemoteException e) { |
| 5487 | // ignore |
| 5488 | } |
| 5489 | return; |
| 5490 | } |
| 5491 | |
| 5492 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5493 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5494 | @Override |
| 5495 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5496 | try { |
| 5497 | callback.onCallForwardingInfoAvailable(info); |
| 5498 | } catch (RemoteException e) { |
| 5499 | // ignore |
| 5500 | } |
| 5501 | } |
| 5502 | |
| 5503 | @Override |
| 5504 | public void onError(int error) { |
| 5505 | try { |
| 5506 | callback.onError(error); |
| 5507 | } catch (RemoteException e) { |
| 5508 | // ignore |
| 5509 | } |
| 5510 | } |
| 5511 | }); |
| 5512 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5513 | } finally { |
| 5514 | Binder.restoreCallingIdentity(identity); |
| 5515 | } |
| 5516 | } |
| 5517 | |
| 5518 | /** |
| 5519 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5520 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5521 | */ |
| 5522 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5523 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5524 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5525 | enforceModifyPermission(); |
| 5526 | long identity = Binder.clearCallingIdentity(); |
| 5527 | try { |
| 5528 | if (DBG) { |
| 5529 | log("setCallForwarding: subId " + subId |
| 5530 | + " callForwardingInfo" + callForwardingInfo); |
| 5531 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5532 | |
| 5533 | Phone phone = getPhone(subId); |
| 5534 | if (phone == null) { |
| 5535 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5536 | callback.accept( |
| 5537 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5538 | } catch (RemoteException e) { |
| 5539 | // ignore |
| 5540 | } |
| 5541 | return; |
| 5542 | } |
| 5543 | |
| 5544 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5545 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5546 | |
| 5547 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5548 | } finally { |
| 5549 | Binder.restoreCallingIdentity(identity); |
| 5550 | } |
| 5551 | } |
| 5552 | |
| 5553 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5554 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5555 | */ |
| 5556 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5557 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5558 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5559 | long identity = Binder.clearCallingIdentity(); |
| 5560 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5561 | |
| 5562 | Phone phone = getPhone(subId); |
| 5563 | if (phone == null) { |
| 5564 | try { |
| 5565 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5566 | } catch (RemoteException e) { |
| 5567 | // ignore |
| 5568 | } |
| 5569 | return; |
| 5570 | } |
| 5571 | |
| 5572 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5573 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5574 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5575 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5576 | } finally { |
| 5577 | Binder.restoreCallingIdentity(identity); |
| 5578 | } |
| 5579 | } |
| 5580 | |
| 5581 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5582 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5583 | */ |
| 5584 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5585 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5586 | enforceModifyPermission(); |
| 5587 | long identity = Binder.clearCallingIdentity(); |
| 5588 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5589 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5590 | |
| 5591 | Phone phone = getPhone(subId); |
| 5592 | if (phone == null) { |
| 5593 | try { |
| 5594 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5595 | } catch (RemoteException e) { |
| 5596 | // ignore |
| 5597 | } |
| 5598 | return; |
| 5599 | } |
| 5600 | |
| 5601 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5602 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5603 | |
| 5604 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5611 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5612 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5613 | * @param subId id of the subscription |
| 5614 | * @param request contains the radio access networks with bands/channels to scan |
| 5615 | * @param messenger callback messenger for scan results or errors |
| 5616 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5617 | * @return the id of the requested scan which can be used to stop the scan. |
| 5618 | */ |
| 5619 | @Override |
| 5620 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5621 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5622 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5623 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5624 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5625 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5626 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5627 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5628 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5629 | .setCallingPid(Binder.getCallingPid()) |
| 5630 | .setCallingUid(Binder.getCallingUid()) |
| 5631 | .setMethod("requestNetworkScan") |
| 5632 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5633 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5634 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5635 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5636 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5637 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5638 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5639 | if (e != null) { |
| 5640 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5641 | throw e; |
| 5642 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5643 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5644 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5645 | } |
| 5646 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5647 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5648 | int callingUid = Binder.getCallingUid(); |
| 5649 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5650 | final long identity = Binder.clearCallingIdentity(); |
| 5651 | try { |
| 5652 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5653 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5654 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5655 | } finally { |
| 5656 | Binder.restoreCallingIdentity(identity); |
| 5657 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5658 | } |
| 5659 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5660 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5661 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5662 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5663 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5664 | boolean hasNetworkScanPermission = |
| 5665 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5666 | == PERMISSION_GRANTED; |
| 5667 | |
| 5668 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5669 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5670 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5671 | } |
| 5672 | |
| 5673 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5674 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5675 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5676 | return new SecurityException("Specific channels must not be" |
| 5677 | + " scanned without location access."); |
| 5678 | } |
| 5679 | } |
| 5680 | } |
| 5681 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5682 | return null; |
| 5683 | } |
| 5684 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5685 | /** |
| 5686 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5687 | * |
| 5688 | * @param subId id of the subscription |
| 5689 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5690 | */ |
| 5691 | @Override |
| 5692 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5693 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5694 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5696 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5697 | final long identity = Binder.clearCallingIdentity(); |
| 5698 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5699 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(identity); |
| 5702 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5706 | * Get the calculated preferred network type. |
| 5707 | * Used for debugging incorrect network type. |
| 5708 | * |
| 5709 | * @return the preferred network type, defined in RILConstants.java. |
| 5710 | */ |
| 5711 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5712 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5713 | final Phone defaultPhone = getDefaultPhone(); |
| 5714 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5715 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5716 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5717 | } |
| 5718 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | final long identity = Binder.clearCallingIdentity(); |
| 5720 | try { |
| 5721 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5722 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5723 | } finally { |
| 5724 | Binder.restoreCallingIdentity(identity); |
| 5725 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5729 | * Get the preferred network type. |
| 5730 | * Used for device configuration by some CDMA operators. |
| 5731 | * |
| 5732 | * @return the preferred network type, defined in RILConstants.java. |
| 5733 | */ |
| 5734 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5735 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5736 | TelephonyPermissions |
| 5737 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5738 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5739 | |
| 5740 | final long identity = Binder.clearCallingIdentity(); |
| 5741 | try { |
| 5742 | if (DBG) log("getPreferredNetworkType"); |
| 5743 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5744 | int networkType = (result != null ? result[0] : -1); |
| 5745 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5746 | return networkType; |
| 5747 | } finally { |
| 5748 | Binder.restoreCallingIdentity(identity); |
| 5749 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5750 | } |
| 5751 | |
| 5752 | /** |
| 5753 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5754 | * |
| 5755 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5756 | * @return true on success; false on any failure. |
| 5757 | */ |
| 5758 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5759 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5760 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5761 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5762 | |
| 5763 | final long identity = Binder.clearCallingIdentity(); |
| 5764 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5765 | Boolean success = (Boolean) sendRequest( |
| 5766 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5767 | |
| 5768 | if (success) { |
| 5769 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5770 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5771 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5772 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5773 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5776 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5777 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5778 | |
| 5779 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5780 | * Get the allowed network types that store in the telephony provider. |
| 5781 | * |
| 5782 | * @param subId the id of the subscription. |
| 5783 | * @return allowedNetworkTypes the allowed network types. |
| 5784 | */ |
| 5785 | @Override |
| 5786 | public long getAllowedNetworkTypes(int subId) { |
| 5787 | TelephonyPermissions |
| 5788 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5789 | mApp, subId, "getAllowedNetworkTypes"); |
| 5790 | |
| 5791 | final long identity = Binder.clearCallingIdentity(); |
| 5792 | try { |
| 5793 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5794 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5795 | } finally { |
| 5796 | Binder.restoreCallingIdentity(identity); |
| 5797 | } |
| 5798 | } |
| 5799 | |
| 5800 | /** |
| 5801 | * Set the allowed network types. |
| 5802 | * |
| 5803 | * @param subId the id of the subscription. |
| 5804 | * @param allowedNetworkTypes the allowed network types. |
| 5805 | * @return true on success; false on any failure. |
| 5806 | */ |
| 5807 | @Override |
| 5808 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5810 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5811 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5812 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5813 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5814 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5815 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5816 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5817 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5818 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5819 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5820 | } |
| 5821 | |
| 5822 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5823 | * Get the allowed network types for certain reason. |
| 5824 | * |
| 5825 | * @param subId the id of the subscription. |
| 5826 | * @param reason the reason the allowed network type change is taking place |
| 5827 | * @return the allowed network types. |
| 5828 | */ |
| 5829 | @Override |
| 5830 | public long getAllowedNetworkTypesForReason(int subId, |
| 5831 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5832 | TelephonyPermissions |
| 5833 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5834 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5835 | final long identity = Binder.clearCallingIdentity(); |
| 5836 | try { |
| 5837 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5838 | } finally { |
| 5839 | Binder.restoreCallingIdentity(identity); |
| 5840 | } |
| 5841 | } |
| 5842 | |
| 5843 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 5844 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 5845 | * @param subId subscription id of the sim card |
| 5846 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 5847 | * This can be passed following states |
| 5848 | * <ol> |
| 5849 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 5850 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 5851 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 5852 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 5853 | * </ol> |
| 5854 | * @return operation result. |
| 5855 | */ |
| 5856 | @Override |
| 5857 | public int setNrDualConnectivityState(int subId, |
| 5858 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 5859 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5860 | mApp, subId, "enableNRDualConnectivity"); |
| 5861 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5862 | final long identity = Binder.clearCallingIdentity(); |
| 5863 | try { |
| 5864 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 5865 | nrDualConnectivityState, subId, |
| 5866 | workSource); |
| 5867 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 5868 | return result; |
| 5869 | } finally { |
| 5870 | Binder.restoreCallingIdentity(identity); |
| 5871 | } |
| 5872 | } |
| 5873 | |
| 5874 | /** |
| 5875 | * Is E-UTRA-NR Dual Connectivity enabled |
| 5876 | * @return true if dual connectivity is enabled else false |
| 5877 | */ |
| 5878 | @Override |
| 5879 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 5880 | TelephonyPermissions |
| 5881 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5882 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 5883 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5884 | final long identity = Binder.clearCallingIdentity(); |
| 5885 | try { |
| 5886 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 5887 | null, subId, workSource); |
| 5888 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 5889 | return isEnabled; |
| 5890 | } finally { |
| 5891 | Binder.restoreCallingIdentity(identity); |
| 5892 | } |
| 5893 | } |
| 5894 | |
| 5895 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame^] | 5896 | * get carrier bandwidth per primary and secondary carrier |
| 5897 | * @param subId subscription id of the sim card |
| 5898 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 5899 | */ |
| 5900 | @Override |
| 5901 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 5902 | TelephonyPermissions |
| 5903 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5904 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 5905 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5906 | final long identity = Binder.clearCallingIdentity(); |
| 5907 | try { |
| 5908 | CarrierBandwidth carrierBandwidth = |
| 5909 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 5910 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 5911 | return carrierBandwidth; |
| 5912 | } finally { |
| 5913 | Binder.restoreCallingIdentity(identity); |
| 5914 | } |
| 5915 | } |
| 5916 | |
| 5917 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5918 | * Get the effective allowed network types on the device. |
| 5919 | * This API will return an intersection of allowed network types for all reasons, |
| 5920 | * including the configuration done through setAllowedNetworkTypes |
| 5921 | * |
| 5922 | * @param subId the id of the subscription. |
| 5923 | * @return the allowed network types |
| 5924 | */ |
| 5925 | @Override |
| 5926 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5927 | TelephonyPermissions |
| 5928 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5929 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5930 | final long identity = Binder.clearCallingIdentity(); |
| 5931 | try { |
| 5932 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5933 | } finally { |
| 5934 | Binder.restoreCallingIdentity(identity); |
| 5935 | } |
| 5936 | } |
| 5937 | |
| 5938 | /** |
| 5939 | * Set the allowed network types of the device and |
| 5940 | * provide the reason triggering the allowed network change. |
| 5941 | * |
| 5942 | * @param subId the id of the subscription. |
| 5943 | * @param reason the reason the allowed network type change is taking place |
| 5944 | * @param allowedNetworkTypes the allowed network types. |
| 5945 | * @return true on success; false on any failure. |
| 5946 | */ |
| 5947 | @Override |
| 5948 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 5949 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 5950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5951 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 5952 | final long identity = Binder.clearCallingIdentity(); |
| 5953 | try { |
| 5954 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 5955 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5956 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5957 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5958 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 5959 | } finally { |
| 5960 | Binder.restoreCallingIdentity(identity); |
| 5961 | } |
| 5962 | } |
| 5963 | |
| 5964 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5965 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5966 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5967 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5968 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5969 | * @hide |
| 5970 | */ |
| 5971 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5972 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5973 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5975 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5976 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5977 | if (phone != null) { |
| 5978 | return phone.hasMatchedTetherApnSetting(); |
| 5979 | } else { |
| 5980 | return false; |
| 5981 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | } finally { |
| 5983 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5984 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5985 | } |
| 5986 | |
| 5987 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5988 | * Enable or disable always reporting signal strength changes from radio. |
| 5989 | * |
| 5990 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5991 | */ |
| 5992 | @Override |
| 5993 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5994 | enforceModifyPermission(); |
| 5995 | enforceSystemCaller(); |
| 5996 | |
| 5997 | final long identity = Binder.clearCallingIdentity(); |
| 5998 | final Phone phone = getPhone(subId); |
| 5999 | try { |
| 6000 | if (phone != null) { |
| 6001 | if (DBG) { |
| 6002 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6003 | + " isEnable=" + isEnable); |
| 6004 | } |
| 6005 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6006 | } else { |
| 6007 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6008 | + subId); |
| 6009 | } |
| 6010 | } finally { |
| 6011 | Binder.restoreCallingIdentity(identity); |
| 6012 | } |
| 6013 | } |
| 6014 | |
| 6015 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6016 | * Get the user enabled state of Mobile Data. |
| 6017 | * |
| 6018 | * TODO: remove and use isUserDataEnabled. |
| 6019 | * This can't be removed now because some vendor codes |
| 6020 | * calls through ITelephony directly while they should |
| 6021 | * use TelephonyManager. |
| 6022 | * |
| 6023 | * @return true on enabled |
| 6024 | */ |
| 6025 | @Override |
| 6026 | public boolean getDataEnabled(int subId) { |
| 6027 | return isUserDataEnabled(subId); |
| 6028 | } |
| 6029 | |
| 6030 | /** |
| 6031 | * Get whether mobile data is enabled per user setting. |
| 6032 | * |
| 6033 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6034 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6035 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6036 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6037 | * |
| 6038 | * @return {@code true} if data is enabled else {@code false} |
| 6039 | */ |
| 6040 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6041 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6042 | try { |
| 6043 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6044 | null); |
| 6045 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6046 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6047 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6048 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6049 | |
| 6050 | final long identity = Binder.clearCallingIdentity(); |
| 6051 | try { |
| 6052 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6053 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6054 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6055 | if (phone != null) { |
| 6056 | boolean retVal = phone.isUserDataEnabled(); |
| 6057 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6058 | return retVal; |
| 6059 | } else { |
| 6060 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6061 | return false; |
| 6062 | } |
| 6063 | } finally { |
| 6064 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6069 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6070 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6071 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6072 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6073 | * @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] | 6074 | */ |
| 6075 | @Override |
| 6076 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6077 | try { |
| 6078 | try { |
| 6079 | mApp.enforceCallingOrSelfPermission( |
| 6080 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6081 | null); |
| 6082 | } catch (Exception e) { |
| 6083 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6084 | "isDataEnabled"); |
| 6085 | } |
| 6086 | } catch (Exception e) { |
| 6087 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6088 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | |
| 6090 | final long identity = Binder.clearCallingIdentity(); |
| 6091 | try { |
| 6092 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6093 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6094 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6095 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6096 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6097 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6098 | return retVal; |
| 6099 | } else { |
| 6100 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6101 | return false; |
| 6102 | } |
| 6103 | } finally { |
| 6104 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6105 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6106 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6107 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6108 | /** |
| 6109 | * Check if data is enabled for a specific reason |
| 6110 | * @param subId Subscription index |
| 6111 | * @param reason the reason the data enable change is taking place |
| 6112 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6113 | */ |
| 6114 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6115 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6116 | @TelephonyManager.DataEnabledReason int reason) { |
| 6117 | try { |
| 6118 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6119 | null); |
| 6120 | } catch (Exception e) { |
| 6121 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6122 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6123 | } |
| 6124 | |
| 6125 | |
| 6126 | final long identity = Binder.clearCallingIdentity(); |
| 6127 | try { |
| 6128 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6129 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6130 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6131 | + " reason=" + reason); |
| 6132 | } |
| 6133 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6134 | if (phone != null) { |
| 6135 | boolean retVal; |
| 6136 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6137 | retVal = phone.isUserDataEnabled(); |
| 6138 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6139 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6140 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6141 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6142 | return retVal; |
| 6143 | } else { |
| 6144 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6145 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6146 | + subId + " retVal=false"); |
| 6147 | } |
| 6148 | return false; |
| 6149 | } |
| 6150 | } finally { |
| 6151 | Binder.restoreCallingIdentity(identity); |
| 6152 | } |
| 6153 | } |
| 6154 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6155 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6156 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6157 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6158 | // Skip the check if it's one of these special uids |
| 6159 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6160 | } |
| 6161 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6162 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6163 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6164 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6165 | || subController == null) return privilegeFromSim; |
| 6166 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6167 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6168 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6169 | |
| 6170 | final long identity = Binder.clearCallingIdentity(); |
| 6171 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6172 | int subId = phone.getSubId(); |
| 6173 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6174 | // A test override is in place for the privileges for this subId, so don't try to |
| 6175 | // read the subscription privileges. |
| 6176 | return privilegeFromSim; |
| 6177 | } |
| 6178 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6179 | SubscriptionManager subManager = (SubscriptionManager) |
| 6180 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6181 | for (String pkg : packages) { |
| 6182 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6183 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6184 | } |
| 6185 | } |
| 6186 | return privilegeFromSim; |
| 6187 | } finally { |
| 6188 | Binder.restoreCallingIdentity(identity); |
| 6189 | } |
| 6190 | } |
| 6191 | |
| 6192 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6193 | String pkgName) { |
| 6194 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6195 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6196 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6197 | || subController == null) return privilegeFromSim; |
| 6198 | |
| 6199 | final long identity = Binder.clearCallingIdentity(); |
| 6200 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6201 | int subId = phone.getSubId(); |
| 6202 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6203 | // A test override is in place for the privileges for this subId, so don't try to |
| 6204 | // read the subscription privileges. |
| 6205 | return privilegeFromSim; |
| 6206 | } |
| 6207 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6208 | SubscriptionManager subManager = (SubscriptionManager) |
| 6209 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6210 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6211 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6212 | } finally { |
| 6213 | Binder.restoreCallingIdentity(identity); |
| 6214 | } |
| 6215 | } |
| 6216 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6217 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6218 | public int getCarrierPrivilegeStatus(int subId) { |
| 6219 | final Phone phone = getPhone(subId); |
| 6220 | if (phone == null) { |
| 6221 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6222 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6223 | } |
| 6224 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6225 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6226 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6227 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6228 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6229 | |
| 6230 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6231 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6232 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6233 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6234 | |
| 6235 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6236 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6237 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6238 | final Phone phone = getPhone(subId); |
| 6239 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6240 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6241 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6242 | } |
| 6243 | UiccProfile profile = |
| 6244 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6245 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6246 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6247 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6248 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6249 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6250 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6251 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6255 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6256 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6257 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6261 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6262 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6263 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6264 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6265 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6266 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6267 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6268 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6269 | } |
| 6270 | |
| 6271 | @Override |
| 6272 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6273 | if (TextUtils.isEmpty(pkgName)) |
| 6274 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6275 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6276 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6277 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6278 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6279 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6280 | continue; |
| 6281 | } |
| 6282 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6283 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6284 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6285 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6286 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6287 | break; |
| 6288 | } |
| 6289 | } |
| 6290 | |
| 6291 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6292 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6293 | |
| 6294 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6295 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6296 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6297 | loge("phoneId " + phoneId + " is not valid."); |
| 6298 | return null; |
| 6299 | } |
| 6300 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6301 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6302 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6303 | return null ; |
| 6304 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6305 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6306 | } |
| 6307 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6308 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6309 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6310 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6311 | List<String> privilegedPackages = new ArrayList<>(); |
| 6312 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6313 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6314 | // has UICC in that slot. |
| 6315 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6316 | if (card.hasCarrierPrivilegeRules()) { |
| 6317 | if (packages == null) { |
| 6318 | // Only check packages in user 0 for now |
| 6319 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6320 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6321 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6322 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6323 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6324 | } |
| 6325 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6326 | PackageInfo pkgInfo = packages.get(p); |
| 6327 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6328 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6329 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6330 | privilegedPackages.add(pkgInfo.packageName); |
| 6331 | } |
| 6332 | } |
| 6333 | } |
| 6334 | } |
| 6335 | return privilegedPackages; |
| 6336 | } |
| 6337 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6338 | @Override |
| 6339 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6340 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6341 | |
| 6342 | final long identity = Binder.clearCallingIdentity(); |
| 6343 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6344 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6345 | try { |
| 6346 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6347 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6348 | } |
| 6349 | } finally { |
| 6350 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6351 | } |
| 6352 | return privilegedPackages; |
| 6353 | } |
| 6354 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6355 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6356 | final Phone phone = getPhone(subId); |
| 6357 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6358 | if (card == null) { |
| 6359 | loge("getIccId: No UICC"); |
| 6360 | return null; |
| 6361 | } |
| 6362 | String iccId = card.getIccId(); |
| 6363 | if (TextUtils.isEmpty(iccId)) { |
| 6364 | loge("getIccId: ICC ID is null or empty."); |
| 6365 | return null; |
| 6366 | } |
| 6367 | return iccId; |
| 6368 | } |
| 6369 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6370 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6371 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6372 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6373 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6374 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6375 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6376 | final long identity = Binder.clearCallingIdentity(); |
| 6377 | try { |
| 6378 | final String iccId = getIccId(subId); |
| 6379 | final Phone phone = getPhone(subId); |
| 6380 | if (phone == null) { |
| 6381 | return false; |
| 6382 | } |
| 6383 | final String subscriberId = phone.getSubscriberId(); |
| 6384 | |
| 6385 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6386 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6387 | + subscriberId + " to " + number); |
| 6388 | } |
| 6389 | |
| 6390 | if (TextUtils.isEmpty(iccId)) { |
| 6391 | return false; |
| 6392 | } |
| 6393 | |
| 6394 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6395 | |
| 6396 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6397 | if (alphaTag == null) { |
| 6398 | editor.remove(alphaTagPrefKey); |
| 6399 | } else { |
| 6400 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6401 | } |
| 6402 | |
| 6403 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6404 | // track all merged IMSIs based on line number |
| 6405 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6406 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6407 | if (number == null) { |
| 6408 | editor.remove(numberPrefKey); |
| 6409 | editor.remove(subscriberPrefKey); |
| 6410 | } else { |
| 6411 | editor.putString(numberPrefKey, number); |
| 6412 | editor.putString(subscriberPrefKey, subscriberId); |
| 6413 | } |
| 6414 | |
| 6415 | editor.commit(); |
| 6416 | return true; |
| 6417 | } finally { |
| 6418 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6419 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6420 | } |
| 6421 | |
| 6422 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6423 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6424 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6425 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6426 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6427 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6428 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6429 | return null; |
| 6430 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6432 | final long identity = Binder.clearCallingIdentity(); |
| 6433 | try { |
| 6434 | String iccId = getIccId(subId); |
| 6435 | if (iccId != null) { |
| 6436 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6437 | if (DBG_MERGE) { |
| 6438 | log("getLine1NumberForDisplay returning " |
| 6439 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6440 | } |
| 6441 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6442 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6443 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6444 | return null; |
| 6445 | } finally { |
| 6446 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6447 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6451 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6452 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6453 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6454 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6455 | return null; |
| 6456 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6457 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6458 | final long identity = Binder.clearCallingIdentity(); |
| 6459 | try { |
| 6460 | String iccId = getIccId(subId); |
| 6461 | if (iccId != null) { |
| 6462 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6463 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6464 | } |
| 6465 | return null; |
| 6466 | } finally { |
| 6467 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6468 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6469 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6470 | |
| 6471 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6472 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6473 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6474 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6475 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6476 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6477 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6478 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6479 | return null; |
| 6480 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6481 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6482 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6483 | // the process, where TelephonyManager was instantiated. |
| 6484 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6485 | final long identity = Binder.clearCallingIdentity(); |
| 6486 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6487 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6488 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6489 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6490 | |
| 6491 | // Figure out what subscribers are currently active |
| 6492 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6493 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6494 | // Only consider subs which match the current subId |
| 6495 | // This logic can be simplified. See b/131189269 for progress. |
| 6496 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6497 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6498 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6499 | |
| 6500 | // First pass, find a number override for an active subscriber |
| 6501 | String mergeNumber = null; |
| 6502 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6503 | for (String key : prefs.keySet()) { |
| 6504 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6505 | final String subscriberId = (String) prefs.get(key); |
| 6506 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6507 | final String iccId = key.substring( |
| 6508 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6509 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6510 | mergeNumber = (String) prefs.get(numberKey); |
| 6511 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6512 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6513 | + " for active subscriber " + subscriberId); |
| 6514 | } |
| 6515 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6516 | break; |
| 6517 | } |
| 6518 | } |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | // Shortcut when no active merged subscribers |
| 6523 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6524 | return null; |
| 6525 | } |
| 6526 | |
| 6527 | // Second pass, find all subscribers under that line override |
| 6528 | final ArraySet<String> result = new ArraySet<>(); |
| 6529 | for (String key : prefs.keySet()) { |
| 6530 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6531 | final String number = (String) prefs.get(key); |
| 6532 | if (mergeNumber.equals(number)) { |
| 6533 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6534 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6535 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6536 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6537 | result.add(subscriberId); |
| 6538 | } |
| 6539 | } |
| 6540 | } |
| 6541 | } |
| 6542 | |
| 6543 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6544 | Arrays.sort(resultArray); |
| 6545 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6546 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6547 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6548 | } |
| 6549 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6550 | } finally { |
| 6551 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6552 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6556 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6557 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6558 | |
| 6559 | final long identity = Binder.clearCallingIdentity(); |
| 6560 | try { |
| 6561 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6562 | TelephonyManager.class); |
| 6563 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6564 | if (subscriberId == null) { |
| 6565 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6566 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6567 | + subId); |
| 6568 | } |
| 6569 | return null; |
| 6570 | } |
| 6571 | |
| 6572 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6573 | .getSubscriptionInfo(subId); |
| 6574 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6575 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6576 | if (groupUuid == null) { |
| 6577 | return new String[]{subscriberId}; |
| 6578 | } |
| 6579 | |
| 6580 | // Get all subscriberIds from the group. |
| 6581 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6582 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6583 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6584 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6585 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6586 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6587 | if (subscriberId != null) { |
| 6588 | mergedSubscriberIds.add(subscriberId); |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6593 | } finally { |
| 6594 | Binder.restoreCallingIdentity(identity); |
| 6595 | |
| 6596 | } |
| 6597 | } |
| 6598 | |
| 6599 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6600 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6601 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6602 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6603 | |
| 6604 | final long identity = Binder.clearCallingIdentity(); |
| 6605 | try { |
| 6606 | final Phone phone = getPhone(subId); |
| 6607 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6608 | } finally { |
| 6609 | Binder.restoreCallingIdentity(identity); |
| 6610 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6611 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6612 | |
| 6613 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6614 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6615 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6616 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6617 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6618 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6619 | |
| 6620 | final long identity = Binder.clearCallingIdentity(); |
| 6621 | try { |
| 6622 | final Phone phone = getPhone(subId); |
| 6623 | if (phone == null) { |
| 6624 | return false; |
| 6625 | } |
| 6626 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6627 | cdmaNonRoamingList); |
| 6628 | } finally { |
| 6629 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6630 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6631 | } |
| 6632 | |
| 6633 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6634 | @Deprecated |
| 6635 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6636 | enforceModifyPermission(); |
| 6637 | |
| 6638 | int returnValue = 0; |
| 6639 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6640 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6641 | if(result.exception == null) { |
| 6642 | if (result.result != null) { |
| 6643 | byte[] responseData = (byte[])(result.result); |
| 6644 | if(responseData.length > oemResp.length) { |
| 6645 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6646 | responseData.length + "bytes. Buffer Size is " + |
| 6647 | oemResp.length + "bytes."); |
| 6648 | } |
| 6649 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6650 | returnValue = responseData.length; |
| 6651 | } |
| 6652 | } else { |
| 6653 | CommandException ex = (CommandException) result.exception; |
| 6654 | returnValue = ex.getCommandError().ordinal(); |
| 6655 | if(returnValue > 0) returnValue *= -1; |
| 6656 | } |
| 6657 | } catch (RuntimeException e) { |
| 6658 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6659 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6660 | if(returnValue > 0) returnValue *= -1; |
| 6661 | } |
| 6662 | |
| 6663 | return returnValue; |
| 6664 | } |
| 6665 | |
| 6666 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6667 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6668 | try { |
| 6669 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6670 | } catch (RuntimeException e) { |
| 6671 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6672 | } |
| 6673 | } |
| 6674 | |
| 6675 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6676 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6677 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6678 | try { |
| 6679 | TelephonyPermissions |
| 6680 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6681 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6682 | } catch (SecurityException e) { |
| 6683 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6684 | throw e; |
| 6685 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6686 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6687 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6688 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6689 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6690 | final long identity = Binder.clearCallingIdentity(); |
| 6691 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6692 | TelephonyPermissions |
| 6693 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6694 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6695 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6696 | } finally { |
| 6697 | Binder.restoreCallingIdentity(identity); |
| 6698 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6699 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6700 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6701 | |
| 6702 | @Override |
| 6703 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6704 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6705 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | |
| 6707 | final long identity = Binder.clearCallingIdentity(); |
| 6708 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6709 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6710 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6711 | } finally { |
| 6712 | Binder.restoreCallingIdentity(identity); |
| 6713 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6714 | } |
| 6715 | |
| 6716 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6717 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6718 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6719 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6720 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6721 | return false; |
| 6722 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | final long identity = Binder.clearCallingIdentity(); |
| 6725 | try { |
| 6726 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6727 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6728 | // In the long run, we may instead need to check if there exists a connection service |
| 6729 | // which can support video calling. |
| 6730 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6731 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | return imsManager.isVtEnabledByPlatform() |
| 6733 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6734 | && imsManager.isVtEnabledByUser(); |
| 6735 | } finally { |
| 6736 | Binder.restoreCallingIdentity(identity); |
| 6737 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6738 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6739 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6740 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6741 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6742 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6743 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6744 | mApp, subId, callingPackage, callingFeatureId, |
| 6745 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | return false; |
| 6747 | } |
| 6748 | |
| 6749 | final long identity = Binder.clearCallingIdentity(); |
| 6750 | try { |
| 6751 | CarrierConfigManager configManager = |
| 6752 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6753 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6754 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6755 | } finally { |
| 6756 | Binder.restoreCallingIdentity(identity); |
| 6757 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6758 | } |
| 6759 | |
| 6760 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6761 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6762 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6763 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6764 | return false; |
| 6765 | } |
| 6766 | |
| 6767 | final long identity = Binder.clearCallingIdentity(); |
| 6768 | try { |
| 6769 | CarrierConfigManager configManager = |
| 6770 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6771 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6773 | } finally { |
| 6774 | Binder.restoreCallingIdentity(identity); |
| 6775 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6776 | } |
| 6777 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6778 | @Override |
| 6779 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6780 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6781 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | @Override |
| 6785 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6786 | final long identity = Binder.clearCallingIdentity(); |
| 6787 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6788 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | } finally { |
| 6790 | Binder.restoreCallingIdentity(identity); |
| 6791 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6792 | } |
| 6793 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6794 | /** |
| 6795 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6796 | * support for the feature and device firmware support. |
| 6797 | * |
| 6798 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6799 | */ |
| 6800 | @Override |
| 6801 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6802 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6803 | final Phone phone = getPhone(subscriptionId); |
| 6804 | if (phone == null) { |
| 6805 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6806 | return false; |
| 6807 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6808 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6809 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6810 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6811 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6812 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6813 | return isCarrierSupported && isDeviceSupported; |
| 6814 | } finally { |
| 6815 | Binder.restoreCallingIdentity(identity); |
| 6816 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6817 | } |
| 6818 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6819 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6820 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6821 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6822 | * 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] | 6823 | */ |
| 6824 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6825 | final long identity = Binder.clearCallingIdentity(); |
| 6826 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6827 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6828 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6829 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6830 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6831 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6832 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6833 | } finally { |
| 6834 | Binder.restoreCallingIdentity(identity); |
| 6835 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6836 | } |
| 6837 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6838 | @Deprecated |
| 6839 | @Override |
| 6840 | public String getDeviceId(String callingPackage) { |
| 6841 | return getDeviceIdWithFeature(callingPackage, null); |
| 6842 | } |
| 6843 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6844 | /** |
| 6845 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6846 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6847 | * |
| 6848 | * <p>Requires Permission: |
| 6849 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6850 | */ |
| 6851 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6852 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6853 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6854 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6855 | return null; |
| 6856 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6857 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6858 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6859 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6860 | return null; |
| 6861 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6862 | |
| 6863 | final long identity = Binder.clearCallingIdentity(); |
| 6864 | try { |
| 6865 | return phone.getDeviceId(); |
| 6866 | } finally { |
| 6867 | Binder.restoreCallingIdentity(identity); |
| 6868 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6869 | } |
| 6870 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6871 | /** |
| 6872 | * {@hide} |
| 6873 | * Returns the IMS Registration Status on a particular subid |
| 6874 | * |
| 6875 | * @param subId |
| 6876 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6877 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6878 | Phone phone = getPhone(subId); |
| 6879 | if (phone != null) { |
| 6880 | return phone.isImsRegistered(); |
| 6881 | } else { |
| 6882 | return false; |
| 6883 | } |
| 6884 | } |
| 6885 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6886 | @Override |
| 6887 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6888 | final long identity = Binder.clearCallingIdentity(); |
| 6889 | try { |
| 6890 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6891 | } finally { |
| 6892 | Binder.restoreCallingIdentity(identity); |
| 6893 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6894 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6895 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6896 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6897 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6898 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6899 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6900 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6901 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6902 | } |
| 6903 | final long identity = Binder.clearCallingIdentity(); |
| 6904 | try { |
| 6905 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6906 | } finally { |
| 6907 | Binder.restoreCallingIdentity(identity); |
| 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6912 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 6913 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 6914 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6915 | final long identity = Binder.clearCallingIdentity(); |
| 6916 | try { |
| 6917 | Phone phone = getPhone(subscriptionId); |
| 6918 | if (phone == null) { |
| 6919 | return null; |
| 6920 | } |
| 6921 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6922 | } finally { |
| 6923 | Binder.restoreCallingIdentity(identity); |
| 6924 | } |
| 6925 | } |
| 6926 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6927 | /** |
| 6928 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6929 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6930 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6931 | final long identity = Binder.clearCallingIdentity(); |
| 6932 | try { |
| 6933 | Phone phone = getPhone(subId); |
| 6934 | if (phone != null) { |
| 6935 | return phone.isWifiCallingEnabled(); |
| 6936 | } else { |
| 6937 | return false; |
| 6938 | } |
| 6939 | } finally { |
| 6940 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6941 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6942 | } |
| 6943 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6944 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6945 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6946 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6947 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6948 | final long identity = Binder.clearCallingIdentity(); |
| 6949 | try { |
| 6950 | Phone phone = getPhone(subId); |
| 6951 | if (phone != null) { |
| 6952 | return phone.isVideoEnabled(); |
| 6953 | } else { |
| 6954 | return false; |
| 6955 | } |
| 6956 | } finally { |
| 6957 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6958 | } |
| 6959 | } |
| 6960 | |
| 6961 | /** |
| 6962 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6963 | * defined in {@link ImsRegistrationImplBase}. |
| 6964 | */ |
| 6965 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6966 | final long identity = Binder.clearCallingIdentity(); |
| 6967 | try { |
| 6968 | Phone phone = getPhone(subId); |
| 6969 | if (phone != null) { |
| 6970 | return phone.getImsRegistrationTech(); |
| 6971 | } else { |
| 6972 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6973 | } |
| 6974 | } finally { |
| 6975 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6976 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6977 | } |
| 6978 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6979 | @Override |
| 6980 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6981 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6982 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6983 | return; |
| 6984 | } |
| 6985 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6986 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6987 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6988 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6989 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6990 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6991 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6992 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6993 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6994 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6995 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6996 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6997 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6998 | // There has been issues when Sms raw table somehow stores orphan |
| 6999 | // fragments. They lead to garbled message when new fragments come |
| 7000 | // in and combined with those stale ones. In case this happens again, |
| 7001 | // user can reset all network settings which will clean up this table. |
| 7002 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7003 | // Clean up IMS settings as well here. |
| 7004 | int slotId = getSlotIndex(subId); |
| 7005 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7006 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7007 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7008 | |
| 7009 | // Erase modem config if erase modem on network setting is enabled. |
| 7010 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7011 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7012 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7013 | sendEraseModemConfig(getDefaultPhone()); |
| 7014 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7015 | } finally { |
| 7016 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7017 | } |
| 7018 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7019 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7020 | private void cleanUpSmsRawTable(Context context) { |
| 7021 | ContentResolver resolver = context.getContentResolver(); |
| 7022 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7023 | resolver.delete(uri, null, null); |
| 7024 | } |
| 7025 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7026 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7027 | public String getSimLocaleForSubscriber(int subId) { |
| 7028 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7029 | final Phone phone = getPhone(subId); |
| 7030 | if (phone == null) { |
| 7031 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7032 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7033 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7034 | final long identity = Binder.clearCallingIdentity(); |
| 7035 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7036 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7037 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7038 | if (info == null) { |
| 7039 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7040 | return null; |
| 7041 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7042 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7043 | // preferences (EF-PL and EF-LI)... |
| 7044 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7045 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7046 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7047 | if (localeFromDefaultSim != null) { |
| 7048 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7049 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7050 | + localeFromDefaultSim); |
| 7051 | return localeFromDefaultSim.toLanguageTag(); |
| 7052 | } else { |
| 7053 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7054 | } |
| 7055 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7056 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7057 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7058 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7059 | // the SIM and carrier preferences does not include a country we add the country |
| 7060 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7061 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7062 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7063 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7064 | return mccLocale.toLanguageTag(); |
| 7065 | } |
| 7066 | |
| 7067 | if (DBG) log("No locale found - returning null"); |
| 7068 | return null; |
| 7069 | } finally { |
| 7070 | Binder.restoreCallingIdentity(identity); |
| 7071 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7072 | } |
| 7073 | |
| 7074 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7075 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7076 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7077 | } |
| 7078 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | /** |
| 7080 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7081 | */ |
| 7082 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7083 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7084 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7085 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7086 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7087 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7088 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7089 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7090 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7091 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7092 | * representing the state of the modem. |
| 7093 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7094 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7095 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7096 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7097 | */ |
| 7098 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7099 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7100 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7101 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7102 | |
| 7103 | final long identity = Binder.clearCallingIdentity(); |
| 7104 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7105 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | } finally { |
| 7107 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7108 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7109 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7110 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7111 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7112 | // less than total activity duration. |
| 7113 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7114 | if (info == null) { |
| 7115 | return false; |
| 7116 | } |
| 7117 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7118 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7119 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7120 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7121 | return (info.isValid() |
| 7122 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7123 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7124 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7125 | && (totalTxTimeMs <= activityDurationMs)); |
| 7126 | } |
| 7127 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7128 | /** |
| 7129 | * {@hide} |
| 7130 | * Returns the service state information on specified subscription. |
| 7131 | */ |
| 7132 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7133 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7134 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7135 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7136 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7137 | return null; |
| 7138 | } |
| 7139 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7140 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7141 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7142 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7143 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7144 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7145 | .setCallingPid(Binder.getCallingPid()) |
| 7146 | .setCallingUid(Binder.getCallingUid()) |
| 7147 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7148 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7149 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7150 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7151 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7152 | .build()); |
| 7153 | |
| 7154 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7155 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7156 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7157 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7158 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7159 | .setCallingPid(Binder.getCallingPid()) |
| 7160 | .setCallingUid(Binder.getCallingUid()) |
| 7161 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7162 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7163 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7164 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7165 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7166 | .build()); |
| 7167 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7168 | boolean hasFinePermission = |
| 7169 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7170 | boolean hasCoarsePermission = |
| 7171 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7172 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7173 | final Phone phone = getPhone(subId); |
| 7174 | if (phone == null) { |
| 7175 | return null; |
| 7176 | } |
| 7177 | |
| 7178 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7179 | .contains(callingPackage); |
| 7180 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7181 | final long identity = Binder.clearCallingIdentity(); |
| 7182 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7183 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7184 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7185 | Rlog.d(LOG_TAG, |
| 7186 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7187 | return null; |
| 7188 | } |
| 7189 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7190 | ServiceState ss = phone.getServiceState(); |
| 7191 | |
| 7192 | // Scrub out the location info in ServiceState depending on what level of access |
| 7193 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7194 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7195 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7196 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | } finally { |
| 7198 | Binder.restoreCallingIdentity(identity); |
| 7199 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7200 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7201 | |
| 7202 | /** |
| 7203 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7204 | * |
| 7205 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7206 | * voicemail ringtone. |
| 7207 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7208 | * PhoneAccount. |
| 7209 | */ |
| 7210 | @Override |
| 7211 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7212 | final long identity = Binder.clearCallingIdentity(); |
| 7213 | try { |
| 7214 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7215 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7216 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7217 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7219 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7220 | } finally { |
| 7221 | Binder.restoreCallingIdentity(identity); |
| 7222 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7223 | } |
| 7224 | |
| 7225 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7226 | * Sets the per-account voicemail ringtone. |
| 7227 | * |
| 7228 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7229 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7230 | * |
| 7231 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7232 | * voicemail ringtone. |
| 7233 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7234 | * PhoneAccount. |
| 7235 | */ |
| 7236 | @Override |
| 7237 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7238 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7239 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7240 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7241 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7242 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7244 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7245 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7246 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7247 | |
| 7248 | final long identity = Binder.clearCallingIdentity(); |
| 7249 | try { |
| 7250 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7251 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7252 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7253 | } |
| 7254 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7255 | } finally { |
| 7256 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7257 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7258 | } |
| 7259 | |
| 7260 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7261 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7262 | * |
| 7263 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7264 | * voicemail vibration setting. |
| 7265 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7266 | */ |
| 7267 | @Override |
| 7268 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | final long identity = Binder.clearCallingIdentity(); |
| 7270 | try { |
| 7271 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7272 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7273 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7274 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7276 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
| 7279 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7280 | } |
| 7281 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7282 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7283 | * Sets the per-account voicemail vibration. |
| 7284 | * |
| 7285 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7286 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7287 | * |
| 7288 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7289 | * voicemail vibration setting. |
| 7290 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7291 | * specific PhoneAccount. |
| 7292 | */ |
| 7293 | @Override |
| 7294 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7295 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7296 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7297 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7298 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7299 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7300 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7301 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7302 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7303 | } |
| 7304 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7305 | final long identity = Binder.clearCallingIdentity(); |
| 7306 | try { |
| 7307 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7308 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7309 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7310 | } |
| 7311 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7312 | } finally { |
| 7313 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7314 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7315 | } |
| 7316 | |
| 7317 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7318 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7319 | * |
| 7320 | * @throws SecurityException if the caller does not have the required permission |
| 7321 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7322 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7323 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7324 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7325 | } |
| 7326 | |
| 7327 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7328 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7329 | * permission. |
| 7330 | * |
| 7331 | * @throws SecurityException if the caller does not have the required permission |
| 7332 | */ |
| 7333 | private void enforceSendSmsPermission() { |
| 7334 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7335 | } |
| 7336 | |
| 7337 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7338 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7339 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7340 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7341 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7342 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7343 | final long identity = Binder.clearCallingIdentity(); |
| 7344 | try { |
| 7345 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7346 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7347 | if (componentName == null) { |
| 7348 | throw new SecurityException( |
| 7349 | "Caller not current active visual voicemail package[null]"); |
| 7350 | } |
| 7351 | String vvmPackage = componentName.getPackageName(); |
| 7352 | if (!callingPackage.equals(vvmPackage)) { |
| 7353 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7354 | + vvmPackage + "]"); |
| 7355 | } |
| 7356 | } finally { |
| 7357 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7358 | } |
| 7359 | } |
| 7360 | |
| 7361 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7362 | * Return the application ID for the app type. |
| 7363 | * |
| 7364 | * @param subId the subscription ID that this request applies to. |
| 7365 | * @param appType the uicc app type. |
| 7366 | * @return Application ID for specificied app type, or null if no uicc. |
| 7367 | */ |
| 7368 | @Override |
| 7369 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7370 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7371 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | |
| 7373 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7374 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7375 | if (phone == null) { |
| 7376 | return null; |
| 7377 | } |
| 7378 | String aid = null; |
| 7379 | try { |
| 7380 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7381 | .getApplicationByType(appType).getAid(); |
| 7382 | } catch (Exception e) { |
| 7383 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7384 | } |
| 7385 | return aid; |
| 7386 | } finally { |
| 7387 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7388 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7389 | } |
| 7390 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7391 | /** |
| 7392 | * Return the Electronic Serial Number. |
| 7393 | * |
| 7394 | * @param subId the subscription ID that this request applies to. |
| 7395 | * @return ESN or null if error. |
| 7396 | */ |
| 7397 | @Override |
| 7398 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7399 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7400 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7401 | |
| 7402 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7403 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7404 | if (phone == null) { |
| 7405 | return null; |
| 7406 | } |
| 7407 | String esn = null; |
| 7408 | try { |
| 7409 | esn = phone.getEsn(); |
| 7410 | } catch (Exception e) { |
| 7411 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7412 | } |
| 7413 | return esn; |
| 7414 | } finally { |
| 7415 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7416 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7417 | } |
| 7418 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7419 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7420 | * Return the Preferred Roaming List Version. |
| 7421 | * |
| 7422 | * @param subId the subscription ID that this request applies to. |
| 7423 | * @return PRLVersion or null if error. |
| 7424 | */ |
| 7425 | @Override |
| 7426 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7427 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7428 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7429 | |
| 7430 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7431 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7432 | if (phone == null) { |
| 7433 | return null; |
| 7434 | } |
| 7435 | String cdmaPrlVersion = null; |
| 7436 | try { |
| 7437 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7438 | } catch (Exception e) { |
| 7439 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7440 | } |
| 7441 | return cdmaPrlVersion; |
| 7442 | } finally { |
| 7443 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7444 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7445 | } |
| 7446 | |
| 7447 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7448 | * Get snapshot of Telephony histograms |
| 7449 | * @return List of Telephony histograms |
| 7450 | * @hide |
| 7451 | */ |
| 7452 | @Override |
| 7453 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7455 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7456 | |
| 7457 | final long identity = Binder.clearCallingIdentity(); |
| 7458 | try { |
| 7459 | return RIL.getTelephonyRILTimingHistograms(); |
| 7460 | } finally { |
| 7461 | Binder.restoreCallingIdentity(identity); |
| 7462 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7463 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7464 | |
| 7465 | /** |
| 7466 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7467 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7468 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7469 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7470 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7471 | * @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] | 7472 | */ |
| 7473 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7474 | @TelephonyManager.SetCarrierRestrictionResult |
| 7475 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7476 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7477 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7478 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7479 | if (carrierRestrictionRules == null) { |
| 7480 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7481 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7482 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7483 | final long identity = Binder.clearCallingIdentity(); |
| 7484 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7485 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7486 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7487 | } finally { |
| 7488 | Binder.restoreCallingIdentity(identity); |
| 7489 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7490 | } |
| 7491 | |
| 7492 | /** |
| 7493 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7494 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7495 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7496 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7497 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7498 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7499 | */ |
| 7500 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7501 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7502 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7503 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | |
| 7505 | final long identity = Binder.clearCallingIdentity(); |
| 7506 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7507 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7508 | if (response instanceof CarrierRestrictionRules) { |
| 7509 | return (CarrierRestrictionRules) response; |
| 7510 | } |
| 7511 | // Response is an Exception of some kind, |
| 7512 | // which is signalled to the user as a NULL retval |
| 7513 | return null; |
| 7514 | } catch (Exception e) { |
| 7515 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7516 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7517 | } finally { |
| 7518 | Binder.restoreCallingIdentity(identity); |
| 7519 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7520 | } |
| 7521 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7522 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7523 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7524 | * @param subId the subscription ID that this action applies to. |
| 7525 | * @param enabled control enable or disable radio. |
| 7526 | * {@hide} |
| 7527 | */ |
| 7528 | @Override |
| 7529 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7530 | enforceModifyPermission(); |
| 7531 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7532 | |
| 7533 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7534 | if (phone == null) { |
| 7535 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7536 | return; |
| 7537 | } |
| 7538 | try { |
| 7539 | phone.carrierActionSetRadioEnabled(enabled); |
| 7540 | } catch (Exception e) { |
| 7541 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | } finally { |
| 7543 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7544 | } |
| 7545 | } |
| 7546 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7547 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7548 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7549 | * network status based on which carrier apps could apply actions accordingly, |
| 7550 | * enable/disable default url handler for example. |
| 7551 | * |
| 7552 | * @param subId the subscription ID that this action applies to. |
| 7553 | * @param report control start/stop reporting the default network status. |
| 7554 | * {@hide} |
| 7555 | */ |
| 7556 | @Override |
| 7557 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7558 | enforceModifyPermission(); |
| 7559 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7560 | |
| 7561 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7562 | if (phone == null) { |
| 7563 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7564 | return; |
| 7565 | } |
| 7566 | try { |
| 7567 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7568 | } catch (Exception e) { |
| 7569 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7570 | } finally { |
| 7571 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7572 | } |
| 7573 | } |
| 7574 | |
| 7575 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7576 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7577 | * @param subId the subscription ID that this action applies to. |
| 7578 | * {@hide} |
| 7579 | */ |
| 7580 | @Override |
| 7581 | public void carrierActionResetAll(int subId) { |
| 7582 | enforceModifyPermission(); |
| 7583 | final Phone phone = getPhone(subId); |
| 7584 | if (phone == null) { |
| 7585 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7586 | return; |
| 7587 | } |
| 7588 | try { |
| 7589 | phone.carrierActionResetAll(); |
| 7590 | } catch (Exception e) { |
| 7591 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7592 | } |
| 7593 | } |
| 7594 | |
| 7595 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7596 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7597 | * bug report is being generated. |
| 7598 | */ |
| 7599 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7600 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7601 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7602 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7603 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7604 | + Binder.getCallingPid() |
| 7605 | + ", uid=" + Binder.getCallingUid() |
| 7606 | + "without permission " |
| 7607 | + android.Manifest.permission.DUMP); |
| 7608 | return; |
| 7609 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7610 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7611 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7612 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7613 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7614 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7615 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7616 | @NonNull String[] args) { |
| 7617 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7618 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7619 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7620 | } |
| 7621 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7622 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7623 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7624 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7625 | * @param reason the reason the data enable change is taking place |
| 7626 | * @param enabled True if enabling the data, otherwise disabling. |
| 7627 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7628 | */ |
| 7629 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7630 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7631 | boolean enabled) { |
| 7632 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7633 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7634 | try { |
| 7635 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7636 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7637 | } catch (SecurityException se) { |
| 7638 | enforceModifyPermission(); |
| 7639 | } |
| 7640 | } else { |
| 7641 | enforceModifyPermission(); |
| 7642 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7643 | |
| 7644 | final long identity = Binder.clearCallingIdentity(); |
| 7645 | try { |
| 7646 | Phone phone = getPhone(subId); |
| 7647 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7648 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7649 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7650 | } else { |
| 7651 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7652 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7653 | } |
| 7654 | } finally { |
| 7655 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7656 | } |
| 7657 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7658 | |
| 7659 | /** |
| 7660 | * Get Client request stats |
| 7661 | * @return List of Client Request Stats |
| 7662 | * @hide |
| 7663 | */ |
| 7664 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7665 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7666 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7667 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7668 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7669 | return null; |
| 7670 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7671 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7672 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7673 | final long identity = Binder.clearCallingIdentity(); |
| 7674 | try { |
| 7675 | if (phone != null) { |
| 7676 | return phone.getClientRequestStats(); |
| 7677 | } |
| 7678 | |
| 7679 | return null; |
| 7680 | } finally { |
| 7681 | Binder.restoreCallingIdentity(identity); |
| 7682 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7683 | } |
| 7684 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7685 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7686 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7687 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7688 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7689 | |
| 7690 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7691 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7692 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7693 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7694 | * @param state State of SIM (power down, power up, pass through) |
| 7695 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7696 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7697 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7698 | * |
| 7699 | **/ |
| 7700 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7701 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7702 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7703 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7704 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7705 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7706 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7707 | final long identity = Binder.clearCallingIdentity(); |
| 7708 | try { |
| 7709 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7710 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7711 | } |
| 7712 | } finally { |
| 7713 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7714 | } |
| 7715 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7716 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7717 | private boolean isUssdApiAllowed(int subId) { |
| 7718 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7719 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7720 | if (configManager == null) { |
| 7721 | return false; |
| 7722 | } |
| 7723 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7724 | if (pb == null) { |
| 7725 | return false; |
| 7726 | } |
| 7727 | return pb.getBoolean( |
| 7728 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7729 | } |
| 7730 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7731 | /** |
| 7732 | * Check if phone is in emergency callback mode |
| 7733 | * @return true if phone is in emergency callback mode |
| 7734 | * @param subId sub id |
| 7735 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7736 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7737 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7738 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7739 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7740 | |
| 7741 | final long identity = Binder.clearCallingIdentity(); |
| 7742 | try { |
| 7743 | if (phone != null) { |
| 7744 | return phone.isInEcm(); |
| 7745 | } else { |
| 7746 | return false; |
| 7747 | } |
| 7748 | } finally { |
| 7749 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7750 | } |
| 7751 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7752 | |
| 7753 | /** |
| 7754 | * Get the current signal strength information for the given subscription. |
| 7755 | * Because this information is not updated when the device is in a low power state |
| 7756 | * it should not be relied-upon to be current. |
| 7757 | * @param subId Subscription index |
| 7758 | * @return the most recent cached signal strength info from the modem |
| 7759 | */ |
| 7760 | @Override |
| 7761 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7762 | final long identity = Binder.clearCallingIdentity(); |
| 7763 | try { |
| 7764 | Phone p = getPhone(subId); |
| 7765 | if (p == null) { |
| 7766 | return null; |
| 7767 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7768 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7769 | return p.getSignalStrength(); |
| 7770 | } finally { |
| 7771 | Binder.restoreCallingIdentity(identity); |
| 7772 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7773 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7774 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7775 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7776 | * Get the current modem radio state for the given slot. |
| 7777 | * @param slotIndex slot index. |
| 7778 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7779 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7780 | * @return the current radio power state from the modem |
| 7781 | */ |
| 7782 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7783 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7784 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7785 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7787 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7788 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7789 | } |
| 7790 | |
| 7791 | final long identity = Binder.clearCallingIdentity(); |
| 7792 | try { |
| 7793 | return phone.getRadioPowerState(); |
| 7794 | } finally { |
| 7795 | Binder.restoreCallingIdentity(identity); |
| 7796 | } |
| 7797 | } |
| 7798 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7799 | } |
| 7800 | |
| 7801 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7802 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7803 | * |
| 7804 | * <p>Requires one of the following permissions: |
| 7805 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7806 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7807 | * privileges. |
| 7808 | * |
| 7809 | * @param subId subscription id |
| 7810 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7811 | * {@code false}. |
| 7812 | */ |
| 7813 | @Override |
| 7814 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7815 | try { |
| 7816 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7817 | null); |
| 7818 | } catch (Exception e) { |
| 7819 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7820 | mApp, subId, "isDataRoamingEnabled"); |
| 7821 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7822 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7823 | boolean isEnabled = false; |
| 7824 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7825 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7826 | Phone phone = getPhone(subId); |
| 7827 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7828 | } finally { |
| 7829 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7830 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7831 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7832 | } |
| 7833 | |
| 7834 | |
| 7835 | /** |
| 7836 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7837 | * |
| 7838 | * <p> Requires permission: |
| 7839 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7840 | * privileges. |
| 7841 | * |
| 7842 | * @param subId subscription id |
| 7843 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7844 | */ |
| 7845 | @Override |
| 7846 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7847 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7848 | mApp, subId, "setDataRoamingEnabled"); |
| 7849 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7850 | final long identity = Binder.clearCallingIdentity(); |
| 7851 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7852 | Phone phone = getPhone(subId); |
| 7853 | if (phone != null) { |
| 7854 | phone.setDataRoamingEnabled(isEnabled); |
| 7855 | } |
| 7856 | } finally { |
| 7857 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7858 | } |
| 7859 | } |
| 7860 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7861 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7862 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7863 | TelephonyPermissions |
| 7864 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7865 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7866 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7867 | boolean isAllowed = true; |
| 7868 | final long identity = Binder.clearCallingIdentity(); |
| 7869 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7870 | Phone phone = getPhone(subId); |
| 7871 | if (phone != null) { |
| 7872 | isAllowed = phone.isCspPlmnEnabled(); |
| 7873 | } |
| 7874 | } finally { |
| 7875 | Binder.restoreCallingIdentity(identity); |
| 7876 | } |
| 7877 | return isAllowed; |
| 7878 | } |
| 7879 | |
| 7880 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7881 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7882 | // Verify that tha callingPackage belongs to the calling UID |
| 7883 | mApp.getSystemService(AppOpsManager.class) |
| 7884 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7885 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7886 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7887 | try { |
| 7888 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7889 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7890 | } catch (SecurityException e) { |
| 7891 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7892 | // has carrier privileges on an active UICC |
| 7893 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7894 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7895 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7896 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7897 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7898 | |
| 7899 | final long identity = Binder.clearCallingIdentity(); |
| 7900 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7901 | UiccController uiccController = UiccController.getInstance(); |
| 7902 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7903 | if (hasReadPermission) { |
| 7904 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7905 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7906 | |
| 7907 | // Remove private info if the caller doesn't have access |
| 7908 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7909 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7910 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7911 | // is available |
| 7912 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7913 | if (card == null || card.getUiccProfile() == null) { |
| 7914 | // assume no access if the card or profile is unavailable |
| 7915 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7916 | continue; |
| 7917 | } |
| 7918 | UiccProfile profile = card.getUiccProfile(); |
| 7919 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7920 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7921 | filteredInfos.add(cardInfo); |
| 7922 | } else { |
| 7923 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7924 | } |
| 7925 | } |
| 7926 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7927 | } finally { |
| 7928 | Binder.restoreCallingIdentity(identity); |
| 7929 | } |
| 7930 | } |
| 7931 | |
| 7932 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7933 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7934 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | final long identity = Binder.clearCallingIdentity(); |
| 7937 | try { |
| 7938 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7939 | if (slots == null) { |
| 7940 | Rlog.i(LOG_TAG, "slots is null."); |
| 7941 | return null; |
| 7942 | } |
| 7943 | |
| 7944 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7945 | for (int i = 0; i < slots.length; i++) { |
| 7946 | UiccSlot slot = slots[i]; |
| 7947 | if (slot == null) { |
| 7948 | continue; |
| 7949 | } |
| 7950 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7951 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | UiccCard card = slot.getUiccCard(); |
| 7953 | if (card != null) { |
| 7954 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7955 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7956 | cardId = slot.getEid(); |
| 7957 | if (TextUtils.isEmpty(cardId)) { |
| 7958 | cardId = slot.getIccId(); |
| 7959 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7960 | } |
| 7961 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7962 | if (cardId != null) { |
| 7963 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7964 | // if cardId is an EID, it's all digits so this is fine |
| 7965 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7966 | } |
| 7967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7968 | int cardState = 0; |
| 7969 | switch (slot.getCardState()) { |
| 7970 | case CARDSTATE_ABSENT: |
| 7971 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7972 | break; |
| 7973 | case CARDSTATE_PRESENT: |
| 7974 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7975 | break; |
| 7976 | case CARDSTATE_ERROR: |
| 7977 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7978 | break; |
| 7979 | case CARDSTATE_RESTRICTED: |
| 7980 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7981 | break; |
| 7982 | default: |
| 7983 | break; |
| 7984 | |
| 7985 | } |
| 7986 | |
| 7987 | infos[i] = new UiccSlotInfo( |
| 7988 | slot.isActive(), |
| 7989 | slot.isEuicc(), |
| 7990 | cardId, |
| 7991 | cardState, |
| 7992 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7993 | slot.isExtendedApduSupported(), |
| 7994 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7995 | } |
| 7996 | return infos; |
| 7997 | } finally { |
| 7998 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7999 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8000 | } |
| 8001 | |
| 8002 | @Override |
| 8003 | public boolean switchSlots(int[] physicalSlots) { |
| 8004 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8005 | |
| 8006 | final long identity = Binder.clearCallingIdentity(); |
| 8007 | try { |
| 8008 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8009 | } finally { |
| 8010 | Binder.restoreCallingIdentity(identity); |
| 8011 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8012 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8013 | |
| 8014 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8015 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8016 | final long identity = Binder.clearCallingIdentity(); |
| 8017 | try { |
| 8018 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8019 | } finally { |
| 8020 | Binder.restoreCallingIdentity(identity); |
| 8021 | } |
| 8022 | } |
| 8023 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8024 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8025 | * A test API to reload the UICC profile. |
| 8026 | * |
| 8027 | * <p>Requires that the calling app has permission |
| 8028 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8029 | * @hide |
| 8030 | */ |
| 8031 | @Override |
| 8032 | public void refreshUiccProfile(int subId) { |
| 8033 | enforceModifyPermission(); |
| 8034 | |
| 8035 | final long identity = Binder.clearCallingIdentity(); |
| 8036 | try { |
| 8037 | Phone phone = getPhone(subId); |
| 8038 | if (phone == null) { |
| 8039 | return; |
| 8040 | } |
| 8041 | UiccCard uiccCard = phone.getUiccCard(); |
| 8042 | if (uiccCard == null) { |
| 8043 | return; |
| 8044 | } |
| 8045 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8046 | if (uiccProfile == null) { |
| 8047 | return; |
| 8048 | } |
| 8049 | uiccProfile.refresh(); |
| 8050 | } finally { |
| 8051 | Binder.restoreCallingIdentity(identity); |
| 8052 | } |
| 8053 | } |
| 8054 | |
| 8055 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8056 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8057 | */ |
| 8058 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8059 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8060 | } |
| 8061 | |
| 8062 | /** |
| 8063 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8064 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8065 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8066 | */ |
| 8067 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8068 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8069 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8070 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8071 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8072 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8073 | return isDataRoamingEnabled; |
| 8074 | } |
| 8075 | |
| 8076 | /** |
| 8077 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8078 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8079 | */ |
| 8080 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8081 | List<Integer> list = TelephonyProperties.default_network(); |
| 8082 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8083 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8084 | return list.get(phoneId); |
| 8085 | } |
| 8086 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8087 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8088 | |
| 8089 | @Override |
| 8090 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8091 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8092 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8093 | |
| 8094 | final long identity = Binder.clearCallingIdentity(); |
| 8095 | try { |
| 8096 | final Phone phone = getPhone(subId); |
| 8097 | if (phone == null) { |
| 8098 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8099 | return; |
| 8100 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8101 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8102 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8103 | if (carrierPrivilegeRules == null) { |
| 8104 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8105 | } else { |
| 8106 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8107 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8108 | } finally { |
| 8109 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8110 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8111 | } |
| 8112 | |
| 8113 | @Override |
| 8114 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8115 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8116 | |
| 8117 | final long identity = Binder.clearCallingIdentity(); |
| 8118 | try { |
| 8119 | final Phone phone = getPhone(subId); |
| 8120 | if (phone == null) { |
| 8121 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8122 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8123 | } |
| 8124 | return phone.getCarrierIdListVersion(); |
| 8125 | } finally { |
| 8126 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8127 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8128 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8129 | |
| 8130 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8131 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8132 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8133 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8134 | mApp, subId, callingPackage, callingFeatureId, |
| 8135 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8136 | return -1; |
| 8137 | } |
| 8138 | |
| 8139 | final long identity = Binder.clearCallingIdentity(); |
| 8140 | try { |
| 8141 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8142 | } finally { |
| 8143 | Binder.restoreCallingIdentity(identity); |
| 8144 | } |
| 8145 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8146 | |
| 8147 | @Override |
| 8148 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8149 | TelephonyPermissions |
| 8150 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8151 | mApp, subId, "getCdmaRoamingMode"); |
| 8152 | |
| 8153 | final long identity = Binder.clearCallingIdentity(); |
| 8154 | try { |
| 8155 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8156 | } finally { |
| 8157 | Binder.restoreCallingIdentity(identity); |
| 8158 | } |
| 8159 | } |
| 8160 | |
| 8161 | @Override |
| 8162 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8163 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8164 | mApp, subId, "setCdmaRoamingMode"); |
| 8165 | |
| 8166 | final long identity = Binder.clearCallingIdentity(); |
| 8167 | try { |
| 8168 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8169 | } finally { |
| 8170 | Binder.restoreCallingIdentity(identity); |
| 8171 | } |
| 8172 | } |
| 8173 | |
| 8174 | @Override |
| 8175 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8176 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8177 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8178 | |
| 8179 | final long identity = Binder.clearCallingIdentity(); |
| 8180 | try { |
| 8181 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8182 | } finally { |
| 8183 | Binder.restoreCallingIdentity(identity); |
| 8184 | } |
| 8185 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8186 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8187 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8188 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8189 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8190 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8191 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8192 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8193 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8194 | } |
| 8195 | final long identity = Binder.clearCallingIdentity(); |
| 8196 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8197 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8198 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8199 | if (phone.getEmergencyNumberTracker() != null |
| 8200 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8201 | emergencyNumberListInternal.put( |
| 8202 | phone.getSubId(), |
| 8203 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8204 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8205 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8206 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8207 | } finally { |
| 8208 | Binder.restoreCallingIdentity(identity); |
| 8209 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8210 | } |
| 8211 | |
| 8212 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8213 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8214 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8215 | if (!exactMatch) { |
| 8216 | TelephonyPermissions |
| 8217 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8218 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8219 | } |
| 8220 | final long identity = Binder.clearCallingIdentity(); |
| 8221 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8222 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8223 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8224 | && phone.getEmergencyNumberTracker() |
| 8225 | .isEmergencyNumber(number, exactMatch)) { |
| 8226 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8227 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8228 | } |
| 8229 | return false; |
| 8230 | } finally { |
| 8231 | Binder.restoreCallingIdentity(identity); |
| 8232 | } |
| 8233 | } |
| 8234 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8235 | /** |
| 8236 | * Update emergency number list for test mode. |
| 8237 | */ |
| 8238 | @Override |
| 8239 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8240 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8241 | "updateEmergencyNumberListTestMode"); |
| 8242 | |
| 8243 | final long identity = Binder.clearCallingIdentity(); |
| 8244 | try { |
| 8245 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8246 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8247 | if (tracker != null) { |
| 8248 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8249 | } |
| 8250 | } |
| 8251 | } finally { |
| 8252 | Binder.restoreCallingIdentity(identity); |
| 8253 | } |
| 8254 | } |
| 8255 | |
| 8256 | /** |
| 8257 | * Get the full emergency number list for test mode. |
| 8258 | */ |
| 8259 | @Override |
| 8260 | public List<String> getEmergencyNumberListTestMode() { |
| 8261 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8262 | "getEmergencyNumberListTestMode"); |
| 8263 | |
| 8264 | final long identity = Binder.clearCallingIdentity(); |
| 8265 | try { |
| 8266 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8267 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8268 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8269 | if (tracker != null) { |
| 8270 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8271 | emergencyNumbers.add(num.getNumber()); |
| 8272 | } |
| 8273 | } |
| 8274 | } |
| 8275 | return new ArrayList<>(emergencyNumbers); |
| 8276 | } finally { |
| 8277 | Binder.restoreCallingIdentity(identity); |
| 8278 | } |
| 8279 | } |
| 8280 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8281 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8282 | public int getEmergencyNumberDbVersion(int subId) { |
| 8283 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8284 | |
| 8285 | final long identity = Binder.clearCallingIdentity(); |
| 8286 | try { |
| 8287 | final Phone phone = getPhone(subId); |
| 8288 | if (phone == null) { |
| 8289 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8290 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8291 | } |
| 8292 | return phone.getEmergencyNumberDbVersion(); |
| 8293 | } finally { |
| 8294 | Binder.restoreCallingIdentity(identity); |
| 8295 | } |
| 8296 | } |
| 8297 | |
| 8298 | @Override |
| 8299 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8300 | enforceModifyPermission(); |
| 8301 | |
| 8302 | final long identity = Binder.clearCallingIdentity(); |
| 8303 | try { |
| 8304 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8305 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8306 | if (tracker != null) { |
| 8307 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8308 | } |
| 8309 | } |
| 8310 | } finally { |
| 8311 | Binder.restoreCallingIdentity(identity); |
| 8312 | } |
| 8313 | } |
| 8314 | |
| 8315 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8316 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8317 | enforceActiveEmergencySessionPermission(); |
| 8318 | |
| 8319 | final long identity = Binder.clearCallingIdentity(); |
| 8320 | try { |
| 8321 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8322 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8323 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8324 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8325 | } |
| 8326 | } |
| 8327 | } finally { |
| 8328 | Binder.restoreCallingIdentity(identity); |
| 8329 | } |
| 8330 | } |
| 8331 | |
| 8332 | @Override |
| 8333 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8334 | enforceActiveEmergencySessionPermission(); |
| 8335 | |
| 8336 | final long identity = Binder.clearCallingIdentity(); |
| 8337 | try { |
| 8338 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8339 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8340 | if (tracker != null) { |
| 8341 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8342 | } |
| 8343 | } |
| 8344 | } finally { |
| 8345 | Binder.restoreCallingIdentity(identity); |
| 8346 | } |
| 8347 | } |
| 8348 | |
| 8349 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8350 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8351 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8352 | Phone phone = getPhone(subId); |
| 8353 | if (phone == null) { |
| 8354 | return null; |
| 8355 | } |
| 8356 | final long identity = Binder.clearCallingIdentity(); |
| 8357 | try { |
| 8358 | UiccProfile profile = UiccController.getInstance() |
| 8359 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8360 | if (profile != null) { |
| 8361 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8362 | } |
| 8363 | } finally { |
| 8364 | Binder.restoreCallingIdentity(identity); |
| 8365 | } |
| 8366 | return null; |
| 8367 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8368 | |
| 8369 | /** |
| 8370 | * Enable or disable a modem stack. |
| 8371 | */ |
| 8372 | @Override |
| 8373 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8374 | enforceModifyPermission(); |
| 8375 | |
| 8376 | final long identity = Binder.clearCallingIdentity(); |
| 8377 | try { |
| 8378 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8379 | if (phone == null) { |
| 8380 | return false; |
| 8381 | } else { |
| 8382 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8383 | } |
| 8384 | } finally { |
| 8385 | Binder.restoreCallingIdentity(identity); |
| 8386 | } |
| 8387 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8388 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8389 | /** |
| 8390 | * Whether a modem stack is enabled or not. |
| 8391 | */ |
| 8392 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8393 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8394 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8395 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8396 | if (phone == null) return false; |
| 8397 | |
| 8398 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8399 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8400 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8401 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8402 | } |
| 8403 | |
| 8404 | final long identity = Binder.clearCallingIdentity(); |
| 8405 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8406 | try { |
| 8407 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8408 | } catch (NoSuchElementException ex) { |
| 8409 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8410 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8411 | } finally { |
| 8412 | Binder.restoreCallingIdentity(identity); |
| 8413 | } |
| 8414 | } |
| 8415 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8416 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8417 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8418 | enforceModifyPermission(); |
| 8419 | |
| 8420 | final long identity = Binder.clearCallingIdentity(); |
| 8421 | try { |
| 8422 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8423 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8424 | .commit(); |
| 8425 | } finally { |
| 8426 | Binder.restoreCallingIdentity(identity); |
| 8427 | } |
| 8428 | } |
| 8429 | |
| 8430 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8431 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8432 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8433 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8434 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8435 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8436 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8437 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8438 | |
| 8439 | final long identity = Binder.clearCallingIdentity(); |
| 8440 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8441 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8442 | } finally { |
| 8443 | Binder.restoreCallingIdentity(identity); |
| 8444 | } |
| 8445 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8446 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8447 | @TelephonyManager.IsMultiSimSupportedResult |
| 8448 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8449 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8450 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8451 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8452 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8453 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8454 | } |
| 8455 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8456 | // supported by the modem, indicate that it is restricted. |
| 8457 | PhoneCapability staticCapability = |
| 8458 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8459 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8460 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8461 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8462 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8463 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8464 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8465 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8466 | } |
| 8467 | // Check if support of multiple SIMs is restricted by carrier |
| 8468 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8469 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8470 | } |
| 8471 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8472 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8473 | } |
| 8474 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8475 | /** |
| 8476 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8477 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8478 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8479 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8480 | * @param numOfSims number of active sims we want to switch to |
| 8481 | */ |
| 8482 | @Override |
| 8483 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8484 | if (numOfSims == 1) { |
| 8485 | enforceModifyPermission(); |
| 8486 | } else { |
| 8487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8488 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8489 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8490 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8491 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8492 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8493 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8494 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8495 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8496 | return; |
| 8497 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8498 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8499 | } finally { |
| 8500 | Binder.restoreCallingIdentity(identity); |
| 8501 | } |
| 8502 | } |
| 8503 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8504 | @Override |
| 8505 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8506 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8507 | Phone phone = getPhone(subId); |
| 8508 | if (phone == null) { |
| 8509 | return false; |
| 8510 | } |
| 8511 | final long identity = Binder.clearCallingIdentity(); |
| 8512 | try { |
| 8513 | UiccCard uiccCard = phone.getUiccCard(); |
| 8514 | if (uiccCard == null) { |
| 8515 | return false; |
| 8516 | } |
| 8517 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8518 | if (uiccProfile == null) { |
| 8519 | return false; |
| 8520 | } |
| 8521 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8522 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8523 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8524 | } |
| 8525 | return false; |
| 8526 | } finally { |
| 8527 | Binder.restoreCallingIdentity(identity); |
| 8528 | } |
| 8529 | } |
| 8530 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8531 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8532 | * Get whether making changes to modem configurations will trigger reboot. |
| 8533 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8534 | */ |
| 8535 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8536 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8537 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8538 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8539 | mApp, subId, callingPackage, callingFeatureId, |
| 8540 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8541 | return false; |
| 8542 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8543 | final long identity = Binder.clearCallingIdentity(); |
| 8544 | try { |
| 8545 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8546 | } finally { |
| 8547 | Binder.restoreCallingIdentity(identity); |
| 8548 | } |
| 8549 | } |
| 8550 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8551 | private void updateModemStateMetrics() { |
| 8552 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8553 | // TODO: check the state for each modem if the api is ready. |
| 8554 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8555 | } |
| 8556 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8557 | @Override |
| 8558 | public int[] getSlotsMapping() { |
| 8559 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8560 | |
| 8561 | final long identity = Binder.clearCallingIdentity(); |
| 8562 | try { |
| 8563 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8564 | // All logical slots should have a mapping to a physical slot. |
| 8565 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8566 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8567 | for (int i = 0; i < slotInfos.length; i++) { |
| 8568 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8569 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8570 | } |
| 8571 | } |
| 8572 | return logicalSlotsMapping; |
| 8573 | } finally { |
| 8574 | Binder.restoreCallingIdentity(identity); |
| 8575 | } |
| 8576 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8577 | |
| 8578 | /** |
| 8579 | * Get the IRadio HAL Version |
| 8580 | */ |
| 8581 | @Override |
| 8582 | public int getRadioHalVersion() { |
| 8583 | Phone phone = getDefaultPhone(); |
| 8584 | if (phone == null) return -1; |
| 8585 | HalVersion hv = phone.getHalVersion(); |
| 8586 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8587 | return hv.major * 100 + hv.minor; |
| 8588 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8589 | |
| 8590 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8591 | * Get the current calling package name. |
| 8592 | * @return the current calling package name |
| 8593 | */ |
| 8594 | @Override |
| 8595 | public String getCurrentPackageName() { |
| 8596 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8597 | } |
| 8598 | |
| 8599 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8600 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8601 | * corresponding network requests on a subId. |
| 8602 | * |
| 8603 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8604 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8605 | * 2) APN is un-metered for this subscription, or |
| 8606 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8607 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8608 | * |
| 8609 | * @return whether data is allowed for a apn type. |
| 8610 | * |
| 8611 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8612 | */ |
| 8613 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8614 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8615 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8616 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8617 | |
| 8618 | // Now that all security checks passes, perform the operation as ourselves. |
| 8619 | final long identity = Binder.clearCallingIdentity(); |
| 8620 | try { |
| 8621 | Phone phone = getPhone(subId); |
| 8622 | if (phone == null) return false; |
| 8623 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8624 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8625 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8626 | } finally { |
| 8627 | Binder.restoreCallingIdentity(identity); |
| 8628 | } |
| 8629 | } |
| 8630 | |
| 8631 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8632 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8633 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8634 | |
| 8635 | // Now that all security checks passes, perform the operation as ourselves. |
| 8636 | final long identity = Binder.clearCallingIdentity(); |
| 8637 | try { |
| 8638 | Phone phone = getPhone(subId); |
| 8639 | if (phone == null) return true; // By default return true. |
| 8640 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8641 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8642 | } finally { |
| 8643 | Binder.restoreCallingIdentity(identity); |
| 8644 | } |
| 8645 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8646 | |
| 8647 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8648 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8649 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8650 | enforceModifyPermission(); |
| 8651 | long token = Binder.clearCallingIdentity(); |
| 8652 | try { |
| 8653 | Phone phone = getPhone(subscriptionId); |
| 8654 | if (phone == null) { |
| 8655 | try { |
| 8656 | if (resultCallback != null) { |
| 8657 | resultCallback.accept(false); |
| 8658 | } |
| 8659 | } catch (RemoteException e) { |
| 8660 | // ignore |
| 8661 | } |
| 8662 | return; |
| 8663 | } |
| 8664 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8665 | Pair.create(specifiers, (x) -> { |
| 8666 | try { |
| 8667 | if (resultCallback != null) { |
| 8668 | resultCallback.accept(x); |
| 8669 | } |
| 8670 | } catch (RemoteException e) { |
| 8671 | // ignore |
| 8672 | } |
| 8673 | }); |
| 8674 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8675 | } finally { |
| 8676 | Binder.restoreCallingIdentity(token); |
| 8677 | } |
| 8678 | } |
| 8679 | |
| 8680 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8681 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8682 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8683 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8684 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8685 | if (iccRecords == null) { |
| 8686 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8687 | return false; |
| 8688 | } |
| 8689 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8690 | } |
| 8691 | |
| 8692 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8693 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8694 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8695 | if (callingPackage == null) { |
| 8696 | callingPackage = getCurrentPackageName(); |
| 8697 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8698 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8699 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8700 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8701 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8702 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8703 | } |
| 8704 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8705 | Intent intent = new Intent(); |
| 8706 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8707 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8708 | // Bring up choose default SMS subscription dialog right now |
| 8709 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8710 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8711 | mApp.startActivity(intent); |
| 8712 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8713 | |
| 8714 | @Override |
| 8715 | public String getMmsUAProfUrl(int subId) { |
| 8716 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8717 | final long identity = Binder.clearCallingIdentity(); |
| 8718 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8719 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8720 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8721 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8722 | return carrierUAProfUrl; |
| 8723 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8724 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8725 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8726 | } finally { |
| 8727 | Binder.restoreCallingIdentity(identity); |
| 8728 | } |
| 8729 | } |
| 8730 | |
| 8731 | @Override |
| 8732 | public String getMmsUserAgent(int subId) { |
| 8733 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8734 | final long identity = Binder.clearCallingIdentity(); |
| 8735 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8736 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8737 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8738 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8739 | return carrierUserAgent; |
| 8740 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8741 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8742 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8743 | } finally { |
| 8744 | Binder.restoreCallingIdentity(identity); |
| 8745 | } |
| 8746 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8747 | |
| 8748 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8749 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8750 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8751 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8752 | final long identity = Binder.clearCallingIdentity(); |
| 8753 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8754 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8755 | if (phone == null) return false; |
| 8756 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8757 | switch (policy) { |
| 8758 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8759 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8760 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8761 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8762 | default: |
| 8763 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8764 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8765 | } finally { |
| 8766 | Binder.restoreCallingIdentity(identity); |
| 8767 | } |
| 8768 | } |
| 8769 | |
| 8770 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8771 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8772 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8773 | enforceModifyPermission(); |
| 8774 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8775 | final long identity = Binder.clearCallingIdentity(); |
| 8776 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8777 | Phone phone = getPhone(subscriptionId); |
| 8778 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8779 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8780 | switch (policy) { |
| 8781 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8782 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8783 | break; |
| 8784 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8785 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 8786 | break; |
| 8787 | default: |
| 8788 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8789 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8790 | } finally { |
| 8791 | Binder.restoreCallingIdentity(identity); |
| 8792 | } |
| 8793 | } |
| 8794 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8795 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8796 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8797 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8798 | * otherwise. |
| 8799 | */ |
| 8800 | @Override |
| 8801 | public void setCepEnabled(boolean isCepEnabled) { |
| 8802 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8803 | |
| 8804 | final long identity = Binder.clearCallingIdentity(); |
| 8805 | try { |
| 8806 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8807 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8808 | Phone defaultPhone = phone.getImsPhone(); |
| 8809 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8810 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8811 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8812 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8813 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8814 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8815 | + imsPhone.getMsisdn()); |
| 8816 | } |
| 8817 | } |
| 8818 | } finally { |
| 8819 | Binder.restoreCallingIdentity(identity); |
| 8820 | } |
| 8821 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8822 | |
| 8823 | /** |
| 8824 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8825 | * |
| 8826 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8827 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8828 | * before being read. |
| 8829 | */ |
| 8830 | @Override |
| 8831 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8832 | isCompressed) { |
| 8833 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8834 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8835 | try { |
| 8836 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8837 | if (configBinder == null) { |
| 8838 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8839 | } else { |
| 8840 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8841 | } |
| 8842 | } catch (RemoteException e) { |
| 8843 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8844 | } |
| 8845 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8846 | |
| 8847 | @Override |
| 8848 | public boolean isIccLockEnabled(int subId) { |
| 8849 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8850 | |
| 8851 | // Now that all security checks passes, perform the operation as ourselves. |
| 8852 | final long identity = Binder.clearCallingIdentity(); |
| 8853 | try { |
| 8854 | Phone phone = getPhone(subId); |
| 8855 | if (phone != null && phone.getIccCard() != null) { |
| 8856 | return phone.getIccCard().getIccLockEnabled(); |
| 8857 | } else { |
| 8858 | return false; |
| 8859 | } |
| 8860 | } finally { |
| 8861 | Binder.restoreCallingIdentity(identity); |
| 8862 | } |
| 8863 | } |
| 8864 | |
| 8865 | /** |
| 8866 | * Set the ICC pin lock enabled or disabled. |
| 8867 | * |
| 8868 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8869 | * three cases: |
| 8870 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8871 | * successfully. |
| 8872 | * - Positive number and zero for remaining password attempts. |
| 8873 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8874 | * |
| 8875 | */ |
| 8876 | @Override |
| 8877 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8878 | enforceModifyPermission(); |
| 8879 | |
| 8880 | Phone phone = getPhone(subId); |
| 8881 | if (phone == null) { |
| 8882 | return 0; |
| 8883 | } |
| 8884 | // Now that all security checks passes, perform the operation as ourselves. |
| 8885 | final long identity = Binder.clearCallingIdentity(); |
| 8886 | try { |
| 8887 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8888 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8889 | return attemptsRemaining; |
| 8890 | |
| 8891 | } catch (Exception e) { |
| 8892 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8893 | } finally { |
| 8894 | Binder.restoreCallingIdentity(identity); |
| 8895 | } |
| 8896 | return 0; |
| 8897 | } |
| 8898 | |
| 8899 | /** |
| 8900 | * Change the ICC password used in ICC pin lock. |
| 8901 | * |
| 8902 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8903 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8904 | * - Positive number and zero for remaining password attempts. |
| 8905 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8906 | * |
| 8907 | */ |
| 8908 | @Override |
| 8909 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8910 | enforceModifyPermission(); |
| 8911 | |
| 8912 | Phone phone = getPhone(subId); |
| 8913 | if (phone == null) { |
| 8914 | return 0; |
| 8915 | } |
| 8916 | // Now that all security checks passes, perform the operation as ourselves. |
| 8917 | final long identity = Binder.clearCallingIdentity(); |
| 8918 | try { |
| 8919 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8920 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8921 | return attemptsRemaining; |
| 8922 | |
| 8923 | } catch (Exception e) { |
| 8924 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8925 | } finally { |
| 8926 | Binder.restoreCallingIdentity(identity); |
| 8927 | } |
| 8928 | return 0; |
| 8929 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8930 | |
| 8931 | /** |
| 8932 | * Request for receiving user activity notification |
| 8933 | */ |
| 8934 | @Override |
| 8935 | public void requestUserActivityNotification() { |
| 8936 | if (!mNotifyUserActivity.get() |
| 8937 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8938 | mNotifyUserActivity.set(true); |
| 8939 | } |
| 8940 | } |
| 8941 | |
| 8942 | /** |
| 8943 | * Called when userActivity is signalled in the power manager. |
| 8944 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8945 | */ |
| 8946 | @Override |
| 8947 | public void userActivity() { |
| 8948 | // *************************************** |
| 8949 | // * Inherited from PhoneWindowManager * |
| 8950 | // *************************************** |
| 8951 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8952 | // WITH ITS LOCKS HELD. |
| 8953 | // |
| 8954 | // This code must be VERY careful about the locks |
| 8955 | // it acquires. |
| 8956 | // In fact, the current code acquires way too many, |
| 8957 | // and probably has lurking deadlocks. |
| 8958 | |
| 8959 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8960 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8961 | } |
| 8962 | |
| 8963 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8964 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8965 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8966 | } |
| 8967 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8968 | |
| 8969 | @Override |
| 8970 | public boolean canConnectTo5GInDsdsMode() { |
| 8971 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 8972 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 8973 | |
| 8974 | @Override |
| 8975 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 8976 | String callingFeatureId) { |
| 8977 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 8978 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 8979 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8980 | } |
| 8981 | |
| 8982 | Phone phone = getPhone(subId); |
| 8983 | if (phone == null) { |
| 8984 | throw new RuntimeException("phone is not available"); |
| 8985 | } |
| 8986 | // Now that all security checks passes, perform the operation as ourselves. |
| 8987 | final long identity = Binder.clearCallingIdentity(); |
| 8988 | try { |
| 8989 | return phone.getEquivalentHomePlmns(); |
| 8990 | } finally { |
| 8991 | Binder.restoreCallingIdentity(identity); |
| 8992 | } |
| 8993 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8994 | } |