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; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 297 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 298 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 299 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 300 | // Parameters of select command. |
| 301 | private static final int SELECT_COMMAND = 0xA4; |
| 302 | private static final int SELECT_P1 = 0x04; |
| 303 | private static final int SELECT_P2 = 0; |
| 304 | private static final int SELECT_P3 = 0x10; |
| 305 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 306 | /** The singleton instance. */ |
| 307 | private static PhoneInterfaceManager sInstance; |
| 308 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 309 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 310 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 311 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 312 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 313 | private AppOpsManager mAppOps; |
| 314 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 315 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 316 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 317 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 318 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 319 | /** User Activity */ |
| 320 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 321 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 322 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 323 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 324 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 325 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 326 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 327 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 328 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 329 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 330 | // String to store multi SIM allowed |
| 331 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 332 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 333 | // The AID of ISD-R. |
| 334 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 335 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 336 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 337 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 338 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 339 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 340 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 341 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 342 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 343 | */ |
| 344 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 345 | "reset_network_erase_modem_config_enabled"; |
| 346 | |
| 347 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 348 | * A request object to use for transmitting data to an ICC. |
| 349 | */ |
| 350 | private static final class IccAPDUArgument { |
| 351 | public int channel, cla, command, p1, p2, p3; |
| 352 | public String data; |
| 353 | |
| 354 | public IccAPDUArgument(int channel, int cla, int command, |
| 355 | int p1, int p2, int p3, String data) { |
| 356 | this.channel = channel; |
| 357 | this.cla = cla; |
| 358 | this.command = command; |
| 359 | this.p1 = p1; |
| 360 | this.p2 = p2; |
| 361 | this.p3 = p3; |
| 362 | this.data = data; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 367 | * A request object to use for transmitting data to an ICC. |
| 368 | */ |
| 369 | private static final class ManualNetworkSelectionArgument { |
| 370 | public OperatorInfo operatorInfo; |
| 371 | public boolean persistSelection; |
| 372 | |
| 373 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 374 | this.operatorInfo = operatorInfo; |
| 375 | this.persistSelection = persistSelection; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 380 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 381 | * request after sending. The main thread will notify the request when it is complete. |
| 382 | */ |
| 383 | private static final class MainThreadRequest { |
| 384 | /** The argument to use for the request */ |
| 385 | public Object argument; |
| 386 | /** The result of the request that is run on the main thread */ |
| 387 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 388 | // The subscriber id that this request applies to. Defaults to |
| 389 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 390 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 392 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 393 | public Phone phone; |
| 394 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 395 | public WorkSource workSource; |
| 396 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | public MainThreadRequest(Object argument) { |
| 398 | this.argument = argument; |
| 399 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 400 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 401 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 402 | this.argument = argument; |
| 403 | if (phone != null) { |
| 404 | this.phone = phone; |
| 405 | } |
| 406 | this.workSource = workSource; |
| 407 | } |
| 408 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 409 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 410 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 411 | if (subId != null) { |
| 412 | this.subId = subId; |
| 413 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 414 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 415 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 418 | private static final class IncomingThirdPartyCallArgs { |
| 419 | public final ComponentName component; |
| 420 | public final String callId; |
| 421 | public final String callerDisplayName; |
| 422 | |
| 423 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 424 | String callerDisplayName) { |
| 425 | this.component = component; |
| 426 | this.callId = callId; |
| 427 | this.callerDisplayName = callerDisplayName; |
| 428 | } |
| 429 | } |
| 430 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | /** |
| 432 | * A handler that processes messages on the main thread in the phone process. Since many |
| 433 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 434 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 435 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 436 | * on, which will be notified when the operation completes and will contain the result of the |
| 437 | * request. |
| 438 | * |
| 439 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 440 | * note that request.result must be set to something non-null for the calling thread to |
| 441 | * unblock. |
| 442 | */ |
| 443 | private final class MainThreadHandler extends Handler { |
| 444 | @Override |
| 445 | public void handleMessage(Message msg) { |
| 446 | MainThreadRequest request; |
| 447 | Message onCompleted; |
| 448 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 449 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 450 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 451 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 452 | |
| 453 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 454 | case CMD_HANDLE_USSD_REQUEST: { |
| 455 | request = (MainThreadRequest) msg.obj; |
| 456 | final Phone phone = getPhoneFromRequest(request); |
| 457 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 458 | String ussdRequest = ussdObject.first; |
| 459 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 460 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 461 | if (!isUssdApiAllowed(request.subId)) { |
| 462 | // Carrier does not support use of this API, return failure. |
| 463 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 464 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 465 | Bundle returnData = new Bundle(); |
| 466 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 467 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 468 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 469 | request.result = true; |
| 470 | notifyRequester(request); |
| 471 | return; |
| 472 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 473 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 474 | try { |
| 475 | request.result = phone != null |
| 476 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 477 | } catch (CallStateException cse) { |
| 478 | request.result = false; |
| 479 | } |
| 480 | // Wake up the requesting thread |
| 481 | notifyRequester(request); |
| 482 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 485 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 487 | final Phone phone = getPhoneFromRequest(request); |
| 488 | request.result = phone != null ? |
| 489 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 490 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 491 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 492 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 493 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 494 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 495 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 497 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 499 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 500 | if (uiccCard == null) { |
| 501 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 502 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 503 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 504 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 505 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 506 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 507 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 508 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 509 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 511 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 512 | break; |
| 513 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 514 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 515 | ar = (AsyncResult) msg.obj; |
| 516 | request = (MainThreadRequest) ar.userObj; |
| 517 | if (ar.exception == null && ar.result != null) { |
| 518 | request.result = ar.result; |
| 519 | } else { |
| 520 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 521 | if (ar.result == null) { |
| 522 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 523 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 524 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 525 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 526 | } else { |
| 527 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 528 | } |
| 529 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 530 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 531 | break; |
| 532 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 533 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 534 | request = (MainThreadRequest) msg.obj; |
| 535 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 536 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 537 | if (uiccCard == null) { |
| 538 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 539 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 540 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | } else { |
| 542 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 543 | request); |
| 544 | uiccCard.iccTransmitApduBasicChannel( |
| 545 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 546 | iccArgument.p3, iccArgument.data, onCompleted); |
| 547 | } |
| 548 | break; |
| 549 | |
| 550 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 551 | ar = (AsyncResult) msg.obj; |
| 552 | request = (MainThreadRequest) ar.userObj; |
| 553 | if (ar.exception == null && ar.result != null) { |
| 554 | request.result = ar.result; |
| 555 | } else { |
| 556 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 557 | if (ar.result == null) { |
| 558 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 559 | } else if (ar.exception instanceof CommandException) { |
| 560 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 561 | ar.exception); |
| 562 | } else { |
| 563 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 564 | } |
| 565 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | break; |
| 568 | |
| 569 | case CMD_EXCHANGE_SIM_IO: |
| 570 | request = (MainThreadRequest) msg.obj; |
| 571 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 572 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | if (uiccCard == null) { |
| 574 | loge("iccExchangeSimIO: No UICC"); |
| 575 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 576 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 577 | } else { |
| 578 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 579 | request); |
| 580 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 581 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 582 | iccArgument.data, onCompleted); |
| 583 | } |
| 584 | break; |
| 585 | |
| 586 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 587 | ar = (AsyncResult) msg.obj; |
| 588 | request = (MainThreadRequest) ar.userObj; |
| 589 | if (ar.exception == null && ar.result != null) { |
| 590 | request.result = ar.result; |
| 591 | } else { |
| 592 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 593 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 594 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 595 | break; |
| 596 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 597 | case CMD_SEND_ENVELOPE: |
| 598 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 599 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 600 | if (uiccCard == null) { |
| 601 | loge("sendEnvelopeWithStatus: No UICC"); |
| 602 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 603 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 604 | } else { |
| 605 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 606 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 607 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 608 | break; |
| 609 | |
| 610 | case EVENT_SEND_ENVELOPE_DONE: |
| 611 | ar = (AsyncResult) msg.obj; |
| 612 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 613 | if (ar.exception == null && ar.result != null) { |
| 614 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 615 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 616 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 617 | if (ar.result == null) { |
| 618 | loge("sendEnvelopeWithStatus: Empty response"); |
| 619 | } else if (ar.exception instanceof CommandException) { |
| 620 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 621 | ar.exception); |
| 622 | } else { |
| 623 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 624 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 625 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 626 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 627 | break; |
| 628 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 629 | case CMD_OPEN_CHANNEL: |
| 630 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 631 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 632 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 633 | if (uiccCard == null) { |
| 634 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 635 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 636 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 637 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 638 | } else { |
| 639 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 640 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 641 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 642 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | break; |
| 644 | |
| 645 | case EVENT_OPEN_CHANNEL_DONE: |
| 646 | ar = (AsyncResult) msg.obj; |
| 647 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 648 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 650 | int[] result = (int[]) ar.result; |
| 651 | int channelId = result[0]; |
| 652 | byte[] selectResponse = null; |
| 653 | if (result.length > 1) { |
| 654 | selectResponse = new byte[result.length - 1]; |
| 655 | for (int i = 1; i < result.length; ++i) { |
| 656 | selectResponse[i - 1] = (byte) result[i]; |
| 657 | } |
| 658 | } |
| 659 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 660 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | if (ar.result == null) { |
| 663 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 665 | if (ar.exception != null) { |
| 666 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 667 | } |
| 668 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 669 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 670 | if (ar.exception instanceof CommandException) { |
| 671 | CommandException.Error error = |
| 672 | ((CommandException) (ar.exception)).getCommandError(); |
| 673 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 674 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 675 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 676 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 680 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 682 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 683 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 684 | break; |
| 685 | |
| 686 | case CMD_CLOSE_CHANNEL: |
| 687 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 688 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 689 | if (uiccCard == null) { |
| 690 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 691 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 692 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 693 | } else { |
| 694 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 695 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 696 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 697 | break; |
| 698 | |
| 699 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 701 | break; |
| 702 | |
| 703 | case CMD_NV_READ_ITEM: |
| 704 | request = (MainThreadRequest) msg.obj; |
| 705 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 706 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 707 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | break; |
| 709 | |
| 710 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | ar = (AsyncResult) msg.obj; |
| 712 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 713 | if (ar.exception == null && ar.result != null) { |
| 714 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 716 | request.result = ""; |
| 717 | if (ar.result == null) { |
| 718 | loge("nvReadItem: Empty response"); |
| 719 | } else if (ar.exception instanceof CommandException) { |
| 720 | loge("nvReadItem: CommandException: " + |
| 721 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 723 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 724 | } |
| 725 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 726 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 727 | break; |
| 728 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 729 | case CMD_NV_WRITE_ITEM: |
| 730 | request = (MainThreadRequest) msg.obj; |
| 731 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 732 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 733 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 734 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case EVENT_NV_WRITE_ITEM_DONE: |
| 738 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 739 | break; |
| 740 | |
| 741 | case CMD_NV_WRITE_CDMA_PRL: |
| 742 | request = (MainThreadRequest) msg.obj; |
| 743 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 744 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 745 | break; |
| 746 | |
| 747 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 748 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 749 | break; |
| 750 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 751 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 752 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 753 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 754 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 755 | break; |
| 756 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 757 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 758 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | break; |
| 760 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 761 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 762 | request = (MainThreadRequest) msg.obj; |
| 763 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 764 | request); |
| 765 | Phone phone = getPhoneFromRequest(request); |
| 766 | if (phone != null) { |
| 767 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 768 | } else { |
| 769 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 770 | request.result = false; |
| 771 | notifyRequester(request); |
| 772 | } |
| 773 | break; |
| 774 | } |
| 775 | |
| 776 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 777 | ar = (AsyncResult) msg.obj; |
| 778 | request = (MainThreadRequest) ar.userObj; |
| 779 | if (ar.exception == null && ar.result != null) { |
| 780 | request.result = ar.result; |
| 781 | } else { |
| 782 | // request.result must be set to something non-null |
| 783 | // for the calling thread to unblock |
| 784 | if (request.result != null) { |
| 785 | request.result = ar.result; |
| 786 | } else { |
| 787 | request.result = false; |
| 788 | } |
| 789 | if (ar.result == null) { |
| 790 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 791 | } else if (ar.exception instanceof CommandException) { |
| 792 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 793 | + ar.exception); |
| 794 | } else { |
| 795 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 796 | } |
| 797 | } |
| 798 | notifyRequester(request); |
| 799 | break; |
| 800 | |
| 801 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 802 | request = (MainThreadRequest) msg.obj; |
| 803 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 804 | Phone phone = getPhoneFromRequest(request); |
| 805 | if (phone != null) { |
| 806 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 807 | request.workSource); |
| 808 | } else { |
| 809 | loge("enableNrDualConnectivity: No phone object"); |
| 810 | request.result = |
| 811 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 812 | notifyRequester(request); |
| 813 | } |
| 814 | break; |
| 815 | } |
| 816 | |
| 817 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 818 | ar = (AsyncResult) msg.obj; |
| 819 | request = (MainThreadRequest) ar.userObj; |
| 820 | if (ar.exception == null) { |
| 821 | request.result = |
| 822 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 823 | } else { |
| 824 | request.result = |
| 825 | TelephonyManager |
| 826 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 827 | if (ar.exception instanceof CommandException) { |
| 828 | CommandException.Error error = |
| 829 | ((CommandException) (ar.exception)).getCommandError(); |
| 830 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 831 | request.result = |
| 832 | TelephonyManager |
| 833 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 834 | } |
| 835 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 836 | + ar.exception); |
| 837 | } else { |
| 838 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 839 | } |
| 840 | } |
| 841 | notifyRequester(request); |
| 842 | break; |
| 843 | } |
| 844 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 845 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 846 | request = (MainThreadRequest) msg.obj; |
| 847 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 848 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 852 | ar = (AsyncResult) msg.obj; |
| 853 | request = (MainThreadRequest) ar.userObj; |
| 854 | if (ar.exception == null && ar.result != null) { |
| 855 | request.result = ar.result; // Integer |
| 856 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 857 | // request.result must be set to something non-null |
| 858 | // for the calling thread to unblock |
| 859 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 860 | if (ar.result == null) { |
| 861 | loge("getPreferredNetworkType: Empty response"); |
| 862 | } else if (ar.exception instanceof CommandException) { |
| 863 | loge("getPreferredNetworkType: CommandException: " + |
| 864 | ar.exception); |
| 865 | } else { |
| 866 | loge("getPreferredNetworkType: Unknown exception"); |
| 867 | } |
| 868 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 869 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 870 | break; |
| 871 | |
| 872 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 873 | request = (MainThreadRequest) msg.obj; |
| 874 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 875 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 876 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 880 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 881 | break; |
| 882 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 883 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 884 | request = (MainThreadRequest)msg.obj; |
| 885 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 886 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 890 | ar = (AsyncResult)msg.obj; |
| 891 | request = (MainThreadRequest)ar.userObj; |
| 892 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 893 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 894 | break; |
| 895 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 896 | case CMD_SET_VOICEMAIL_NUMBER: |
| 897 | request = (MainThreadRequest) msg.obj; |
| 898 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 899 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 900 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 901 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 902 | break; |
| 903 | |
| 904 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 905 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 906 | break; |
| 907 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 908 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 909 | request = (MainThreadRequest) msg.obj; |
| 910 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 911 | request); |
| 912 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 913 | break; |
| 914 | |
| 915 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 916 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 917 | break; |
| 918 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 919 | case CMD_PERFORM_NETWORK_SCAN: |
| 920 | request = (MainThreadRequest) msg.obj; |
| 921 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 922 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 923 | break; |
| 924 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 925 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 926 | request = (MainThreadRequest) msg.obj; |
| 927 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 928 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 929 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 930 | request.argument; |
| 931 | int callForwardingReason = args.first; |
| 932 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 933 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 934 | } |
| 935 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 936 | ar = (AsyncResult) msg.obj; |
| 937 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 938 | TelephonyManager.CallForwardingInfoCallback callback = |
| 939 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 940 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 941 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 942 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 943 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 944 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 945 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 946 | // any service for voice call. |
| 947 | if ((callForwardInfo.serviceClass |
| 948 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 949 | callForwardingInfo = new CallForwardingInfo(true, |
| 950 | callForwardInfo.reason, |
| 951 | callForwardInfo.number, |
| 952 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 953 | break; |
| 954 | } |
| 955 | } |
| 956 | // Didn't find a call forward info for voice call. |
| 957 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 958 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 959 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 960 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 961 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 962 | } else { |
| 963 | if (ar.result == null) { |
| 964 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 965 | } |
| 966 | if (ar.exception != null) { |
| 967 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 968 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 969 | int errorCode = TelephonyManager |
| 970 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 971 | if (ar.exception instanceof CommandException) { |
| 972 | CommandException.Error error = |
| 973 | ((CommandException) (ar.exception)).getCommandError(); |
| 974 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 975 | errorCode = TelephonyManager |
| 976 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 977 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 978 | errorCode = TelephonyManager |
| 979 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 980 | } |
| 981 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 983 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 984 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 985 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 986 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 987 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 988 | request = (MainThreadRequest) msg.obj; |
| 989 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 990 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 991 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 992 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 993 | request.argument).first; |
| 994 | request.phone.setCallForwardingOption( |
| 995 | callForwardingInfoToSet.isEnabled() |
| 996 | ? CommandsInterface.CF_ACTION_ENABLE |
| 997 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 998 | callForwardingInfoToSet.getReason(), |
| 999 | callForwardingInfoToSet.getNumber(), |
| 1000 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1001 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1002 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1003 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1004 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1005 | ar = (AsyncResult) msg.obj; |
| 1006 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1007 | Consumer<Integer> callback = |
| 1008 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1009 | request.argument).second; |
| 1010 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1011 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1012 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1013 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1014 | if (ar.exception instanceof CommandException) { |
| 1015 | CommandException.Error error = |
| 1016 | ((CommandException) (ar.exception)).getCommandError(); |
| 1017 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1018 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1019 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1020 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1021 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1022 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | callback.accept(errorCode); |
| 1026 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1027 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1028 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1029 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1030 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1031 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1033 | request = (MainThreadRequest) msg.obj; |
| 1034 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1035 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1036 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1038 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1040 | ar = (AsyncResult) msg.obj; |
| 1041 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1043 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1044 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1045 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1046 | // Service Class is a bit mask per 3gpp 27.007. |
| 1047 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1048 | if (callForwardResults.length > 1 |
| 1049 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1051 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1052 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1053 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1054 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1055 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1056 | } |
| 1057 | } else { |
| 1058 | if (ar.result == null) { |
| 1059 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1060 | } |
| 1061 | if (ar.exception != null) { |
| 1062 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1063 | } |
| 1064 | if (ar.exception instanceof CommandException) { |
| 1065 | CommandException.Error error = |
| 1066 | ((CommandException) (ar.exception)).getCommandError(); |
| 1067 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1068 | callForwardingStatus = |
| 1069 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1070 | } |
| 1071 | } |
| 1072 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1073 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1074 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1075 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1076 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1078 | request = (MainThreadRequest) msg.obj; |
| 1079 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1080 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1081 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1082 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1083 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1084 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1085 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1086 | ar = (AsyncResult) msg.obj; |
| 1087 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1088 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1089 | Consumer<Integer> callback = |
| 1090 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1091 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1092 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1093 | if (ar.exception instanceof CommandException) { |
| 1094 | CommandException.Error error = |
| 1095 | ((CommandException) (ar.exception)).getCommandError(); |
| 1096 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1097 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1098 | } else { |
| 1099 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1100 | } |
| 1101 | } else { |
| 1102 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1103 | } |
| 1104 | } else { |
| 1105 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1106 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1107 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1108 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1109 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1110 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1111 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1112 | ar = (AsyncResult) msg.obj; |
| 1113 | request = (MainThreadRequest) ar.userObj; |
| 1114 | CellNetworkScanResult cellScanResult; |
| 1115 | if (ar.exception == null && ar.result != null) { |
| 1116 | cellScanResult = new CellNetworkScanResult( |
| 1117 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1118 | (List<OperatorInfo>) ar.result); |
| 1119 | } else { |
| 1120 | if (ar.result == null) { |
| 1121 | loge("getCellNetworkScanResults: Empty response"); |
| 1122 | } |
| 1123 | if (ar.exception != null) { |
| 1124 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1125 | } |
| 1126 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1127 | if (ar.exception instanceof CommandException) { |
| 1128 | CommandException.Error error = |
| 1129 | ((CommandException) (ar.exception)).getCommandError(); |
| 1130 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1131 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1132 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1133 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1134 | } |
| 1135 | } |
| 1136 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1137 | } |
| 1138 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1139 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1140 | break; |
| 1141 | |
| 1142 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1143 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1144 | ManualNetworkSelectionArgument selArg = |
| 1145 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1146 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1147 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1148 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1149 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1150 | break; |
| 1151 | |
| 1152 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1153 | ar = (AsyncResult) msg.obj; |
| 1154 | request = (MainThreadRequest) ar.userObj; |
| 1155 | if (ar.exception == null) { |
| 1156 | request.result = true; |
| 1157 | } else { |
| 1158 | request.result = false; |
| 1159 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1160 | } |
| 1161 | notifyRequester(request); |
| 1162 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1163 | break; |
| 1164 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1165 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1166 | request = (MainThreadRequest) msg.obj; |
| 1167 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1168 | if (defaultPhone != null) { |
| 1169 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1170 | } else { |
| 1171 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1172 | Bundle bundle = new Bundle(); |
| 1173 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1174 | new ModemActivityInfo(0, 0, 0, |
| 1175 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1176 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1177 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1178 | break; |
| 1179 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1180 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1181 | ar = (AsyncResult) msg.obj; |
| 1182 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1183 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1184 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1185 | ModemActivityInfo ret = null; |
| 1186 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1187 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1188 | // Update the last modem activity info and the result of the request. |
| 1189 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1190 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1191 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1192 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1193 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1194 | .getTransmitTimeMillis(); |
| 1195 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1196 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1197 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1198 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1199 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1200 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1201 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1202 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1203 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1204 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1205 | info.getReceiveTimeMillis() |
| 1206 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1207 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1208 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1209 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1210 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1211 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1212 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1213 | } else { |
| 1214 | if (ar.result == null) { |
| 1215 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1216 | error = TelephonyManager.ModemActivityInfoException |
| 1217 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1218 | } else if (ar.exception instanceof CommandException) { |
| 1219 | loge("queryModemActivityInfo: CommandException: " + |
| 1220 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1221 | error = TelephonyManager.ModemActivityInfoException |
| 1222 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1223 | } else { |
| 1224 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1225 | error = TelephonyManager.ModemActivityInfoException |
| 1226 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1227 | } |
| 1228 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1229 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1230 | if (ret != null) { |
| 1231 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1232 | } else { |
| 1233 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1234 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1235 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1236 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1237 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1238 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1239 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1240 | case CMD_SET_ALLOWED_CARRIERS: |
| 1241 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1242 | CarrierRestrictionRules argument = |
| 1243 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1244 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1245 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1246 | break; |
| 1247 | |
| 1248 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1249 | ar = (AsyncResult) msg.obj; |
| 1250 | request = (MainThreadRequest) ar.userObj; |
| 1251 | if (ar.exception == null && ar.result != null) { |
| 1252 | request.result = ar.result; |
| 1253 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1254 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1255 | if (ar.exception instanceof CommandException) { |
| 1256 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1257 | CommandException.Error error = |
| 1258 | ((CommandException) (ar.exception)).getCommandError(); |
| 1259 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1260 | request.result = |
| 1261 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1262 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1263 | } else { |
| 1264 | loge("setAllowedCarriers: Unknown exception"); |
| 1265 | } |
| 1266 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1267 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1268 | break; |
| 1269 | |
| 1270 | case CMD_GET_ALLOWED_CARRIERS: |
| 1271 | request = (MainThreadRequest) msg.obj; |
| 1272 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1273 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1274 | break; |
| 1275 | |
| 1276 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1277 | ar = (AsyncResult) msg.obj; |
| 1278 | request = (MainThreadRequest) ar.userObj; |
| 1279 | if (ar.exception == null && ar.result != null) { |
| 1280 | request.result = ar.result; |
| 1281 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1282 | request.result = new IllegalStateException( |
| 1283 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1284 | if (ar.result == null) { |
| 1285 | loge("getAllowedCarriers: Empty response"); |
| 1286 | } else if (ar.exception instanceof CommandException) { |
| 1287 | loge("getAllowedCarriers: CommandException: " + |
| 1288 | ar.exception); |
| 1289 | } else { |
| 1290 | loge("getAllowedCarriers: Unknown exception"); |
| 1291 | } |
| 1292 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1293 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1294 | break; |
| 1295 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1296 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1297 | ar = (AsyncResult) msg.obj; |
| 1298 | request = (MainThreadRequest) ar.userObj; |
| 1299 | if (ar.exception == null && ar.result != null) { |
| 1300 | request.result = ar.result; |
| 1301 | } else { |
| 1302 | request.result = new IllegalArgumentException( |
| 1303 | "Failed to retrieve Forbidden Plmns"); |
| 1304 | if (ar.result == null) { |
| 1305 | loge("getForbiddenPlmns: Empty response"); |
| 1306 | } else { |
| 1307 | loge("getForbiddenPlmns: Unknown exception"); |
| 1308 | } |
| 1309 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1310 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1311 | break; |
| 1312 | |
| 1313 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1314 | request = (MainThreadRequest) msg.obj; |
| 1315 | uiccCard = getUiccCardFromRequest(request); |
| 1316 | if (uiccCard == null) { |
| 1317 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1318 | request.result = new IllegalArgumentException( |
| 1319 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1320 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1321 | break; |
| 1322 | } |
| 1323 | Integer appType = (Integer) request.argument; |
| 1324 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1325 | if (uiccApp == null) { |
| 1326 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1327 | + appType); |
| 1328 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1329 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1330 | break; |
| 1331 | } else { |
| 1332 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1333 | + " specified type -- " + appType); |
| 1334 | } |
| 1335 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1336 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1337 | onCompleted); |
| 1338 | break; |
| 1339 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1340 | case CMD_SWITCH_SLOTS: |
| 1341 | request = (MainThreadRequest) msg.obj; |
| 1342 | int[] physicalSlots = (int[]) request.argument; |
| 1343 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1344 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1345 | break; |
| 1346 | |
| 1347 | case EVENT_SWITCH_SLOTS_DONE: |
| 1348 | ar = (AsyncResult) msg.obj; |
| 1349 | request = (MainThreadRequest) ar.userObj; |
| 1350 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1351 | notifyRequester(request); |
| 1352 | break; |
| 1353 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1354 | request = (MainThreadRequest) msg.obj; |
| 1355 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1356 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1357 | break; |
| 1358 | |
| 1359 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1360 | ar = (AsyncResult) msg.obj; |
| 1361 | request = (MainThreadRequest) ar.userObj; |
| 1362 | if (ar.exception != null) { |
| 1363 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1364 | } else { |
| 1365 | int mode = ((int[]) ar.result)[0]; |
| 1366 | if (mode == 0) { |
| 1367 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1368 | } else { |
| 1369 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1370 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1371 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1372 | notifyRequester(request); |
| 1373 | break; |
| 1374 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1375 | request = (MainThreadRequest) msg.obj; |
| 1376 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1377 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1378 | break; |
| 1379 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1380 | ar = (AsyncResult) msg.obj; |
| 1381 | request = (MainThreadRequest) ar.userObj; |
| 1382 | if (ar.exception != null) { |
| 1383 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1384 | } else { |
| 1385 | request.result = ((int[]) ar.result)[0]; |
| 1386 | } |
| 1387 | notifyRequester(request); |
| 1388 | break; |
| 1389 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1390 | request = (MainThreadRequest) msg.obj; |
| 1391 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1392 | int mode = (int) request.argument; |
| 1393 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1394 | break; |
| 1395 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1396 | ar = (AsyncResult) msg.obj; |
| 1397 | request = (MainThreadRequest) ar.userObj; |
| 1398 | request.result = ar.exception == null; |
| 1399 | notifyRequester(request); |
| 1400 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1401 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1402 | request = (MainThreadRequest) msg.obj; |
| 1403 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1404 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1405 | break; |
| 1406 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1407 | ar = (AsyncResult) msg.obj; |
| 1408 | request = (MainThreadRequest) ar.userObj; |
| 1409 | if (ar.exception != null) { |
| 1410 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1411 | } else { |
| 1412 | request.result = ((int[]) ar.result)[0]; |
| 1413 | } |
| 1414 | notifyRequester(request); |
| 1415 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1416 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1417 | request = (MainThreadRequest) msg.obj; |
| 1418 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1419 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1420 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1421 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1422 | break; |
| 1423 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1424 | ar = (AsyncResult) msg.obj; |
| 1425 | request = (MainThreadRequest) ar.userObj; |
| 1426 | request.result = ar.exception == null; |
| 1427 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1428 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1429 | case CMD_GET_ALL_CELL_INFO: |
| 1430 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1431 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1432 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1433 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1434 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1435 | ar = (AsyncResult) msg.obj; |
| 1436 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1437 | // If a timeout occurs, the response will be null |
| 1438 | request.result = (ar.exception == null && ar.result != null) |
| 1439 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1440 | synchronized (request) { |
| 1441 | request.notifyAll(); |
| 1442 | } |
| 1443 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1444 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1445 | request = (MainThreadRequest) msg.obj; |
| 1446 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1447 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1448 | break; |
| 1449 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1450 | ar = (AsyncResult) msg.obj; |
| 1451 | request = (MainThreadRequest) ar.userObj; |
| 1452 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1453 | try { |
| 1454 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1455 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1456 | cb.onError( |
| 1457 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1458 | ar.exception.getClass().getName(), |
| 1459 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1460 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1461 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1462 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1463 | } else { |
| 1464 | // use the result as returned |
| 1465 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1466 | } |
| 1467 | } catch (RemoteException re) { |
| 1468 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1469 | } |
| 1470 | break; |
| 1471 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1472 | request = (MainThreadRequest) msg.obj; |
| 1473 | WorkSource ws = (WorkSource) request.argument; |
| 1474 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1475 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1476 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1477 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1478 | ar = (AsyncResult) msg.obj; |
| 1479 | request = (MainThreadRequest) ar.userObj; |
| 1480 | if (ar.exception == null) { |
| 1481 | request.result = ar.result; |
| 1482 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1483 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1484 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1485 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | synchronized (request) { |
| 1489 | request.notifyAll(); |
| 1490 | } |
| 1491 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1492 | case CMD_MODEM_REBOOT: |
| 1493 | request = (MainThreadRequest) msg.obj; |
| 1494 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1495 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1496 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1497 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1498 | handleNullReturnEvent(msg, "rebootModem"); |
| 1499 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1500 | case CMD_REQUEST_ENABLE_MODEM: |
| 1501 | request = (MainThreadRequest) msg.obj; |
| 1502 | boolean enable = (boolean) request.argument; |
| 1503 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1504 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1505 | PhoneConfigurationManager.getInstance() |
| 1506 | .enablePhone(request.phone, enable, onCompleted); |
| 1507 | break; |
| 1508 | case EVENT_ENABLE_MODEM_DONE: |
| 1509 | ar = (AsyncResult) msg.obj; |
| 1510 | request = (MainThreadRequest) ar.userObj; |
| 1511 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1512 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1513 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1514 | if ((boolean) request.result) { |
| 1515 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1516 | updateModemStateMetrics(); |
| 1517 | } else { |
| 1518 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1519 | + ar.exception); |
| 1520 | } |
| 1521 | notifyRequester(request); |
| 1522 | break; |
| 1523 | case CMD_GET_MODEM_STATUS: |
| 1524 | request = (MainThreadRequest) msg.obj; |
| 1525 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1526 | PhoneConfigurationManager.getInstance() |
| 1527 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1528 | break; |
| 1529 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1530 | ar = (AsyncResult) msg.obj; |
| 1531 | request = (MainThreadRequest) ar.userObj; |
| 1532 | int id = request.phone.getPhoneId(); |
| 1533 | if (ar.exception == null && ar.result != null) { |
| 1534 | request.result = ar.result; |
| 1535 | //update the cache as modem status has changed |
| 1536 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1537 | (boolean) request.result); |
| 1538 | } else { |
| 1539 | // Return true if modem status cannot be retrieved. For most cases, |
| 1540 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1541 | // and disable modem are not supported. Modem is always on. |
| 1542 | // TODO: this should be fixed in R to support a third |
| 1543 | // status UNKNOWN b/131631629 |
| 1544 | request.result = true; |
| 1545 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1546 | + ar.exception); |
| 1547 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1548 | notifyRequester(request); |
| 1549 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1550 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1551 | request = (MainThreadRequest) msg.obj; |
| 1552 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1553 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1554 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1555 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1556 | break; |
| 1557 | } |
| 1558 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1559 | ar = (AsyncResult) msg.obj; |
| 1560 | request = (MainThreadRequest) ar.userObj; |
| 1561 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1562 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1563 | args.second.accept(ar.exception == null); |
| 1564 | notifyRequester(request); |
| 1565 | break; |
| 1566 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1567 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1568 | ar = (AsyncResult) msg.obj; |
| 1569 | request = (MainThreadRequest) ar.userObj; |
| 1570 | if (ar.exception == null && ar.result != null) { |
| 1571 | request.result = ar.result; |
| 1572 | } else { |
| 1573 | request.result = -1; |
| 1574 | loge("Failed to set Forbidden Plmns"); |
| 1575 | if (ar.result == null) { |
| 1576 | loge("setForbidenPlmns: Empty response"); |
| 1577 | } else if (ar.exception != null) { |
| 1578 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1579 | request.result = -1; |
| 1580 | } else { |
| 1581 | loge("setForbiddenPlmns: Unknown exception"); |
| 1582 | } |
| 1583 | } |
| 1584 | notifyRequester(request); |
| 1585 | break; |
| 1586 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1587 | request = (MainThreadRequest) msg.obj; |
| 1588 | uiccCard = getUiccCardFromRequest(request); |
| 1589 | if (uiccCard == null) { |
| 1590 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1591 | request.result = -1; |
| 1592 | notifyRequester(request); |
| 1593 | break; |
| 1594 | } |
| 1595 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1596 | (Pair<Integer, List<String>>) request.argument; |
| 1597 | appType = setFplmnsArgs.first; |
| 1598 | List<String> fplmns = setFplmnsArgs.second; |
| 1599 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1600 | if (uiccApp == null) { |
| 1601 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1602 | request.result = -1; |
| 1603 | loge("Failed to get UICC App"); |
| 1604 | notifyRequester(request); |
| 1605 | } else { |
| 1606 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1607 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1608 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1609 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1610 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1611 | case CMD_ERASE_MODEM_CONFIG: |
| 1612 | request = (MainThreadRequest) msg.obj; |
| 1613 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1614 | defaultPhone.eraseModemConfig(onCompleted); |
| 1615 | break; |
| 1616 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1617 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1618 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1619 | |
| 1620 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1621 | request = (MainThreadRequest) msg.obj; |
| 1622 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1623 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1624 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1625 | changed.first, changed.second, onCompleted); |
| 1626 | break; |
| 1627 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_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 | |
| 1638 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1639 | request = (MainThreadRequest) msg.obj; |
| 1640 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1641 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1642 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1643 | enabled.first, enabled.second, onCompleted); |
| 1644 | break; |
| 1645 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1646 | ar = (AsyncResult) msg.obj; |
| 1647 | request = (MainThreadRequest) ar.userObj; |
| 1648 | if (ar.exception == null) { |
| 1649 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1650 | } else { |
| 1651 | request.result = msg.arg1; |
| 1652 | } |
| 1653 | notifyRequester(request); |
| 1654 | break; |
| 1655 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1656 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1657 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1658 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1659 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1660 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1661 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1662 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1663 | default: |
| 1664 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1665 | break; |
| 1666 | } |
| 1667 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1668 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1669 | private void notifyRequester(MainThreadRequest request) { |
| 1670 | synchronized (request) { |
| 1671 | request.notifyAll(); |
| 1672 | } |
| 1673 | } |
| 1674 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1675 | private void handleNullReturnEvent(Message msg, String command) { |
| 1676 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1677 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1678 | if (ar.exception == null) { |
| 1679 | request.result = true; |
| 1680 | } else { |
| 1681 | request.result = false; |
| 1682 | if (ar.exception instanceof CommandException) { |
| 1683 | loge(command + ": CommandException: " + ar.exception); |
| 1684 | } else { |
| 1685 | loge(command + ": Unknown exception"); |
| 1686 | } |
| 1687 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1688 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1689 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | /** |
| 1693 | * Posts the specified command to be executed on the main thread, |
| 1694 | * waits for the request to complete, and returns the result. |
| 1695 | * @see #sendRequestAsync |
| 1696 | */ |
| 1697 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1698 | return sendRequest( |
| 1699 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | /** |
| 1703 | * Posts the specified command to be executed on the main thread, |
| 1704 | * waits for the request to complete, and returns the result. |
| 1705 | * @see #sendRequestAsync |
| 1706 | */ |
| 1707 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1708 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1709 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 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 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1717 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1718 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | /** |
| 1722 | * Posts the specified command to be executed on the main thread, |
| 1723 | * waits for the request to complete, and returns the result. |
| 1724 | * @see #sendRequestAsync |
| 1725 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1726 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1727 | return sendRequest(command, argument, subId, null, workSource); |
| 1728 | } |
| 1729 | |
| 1730 | /** |
| 1731 | * Posts the specified command to be executed on the main thread, |
| 1732 | * waits for the request to complete, and returns the result. |
| 1733 | * @see #sendRequestAsync |
| 1734 | */ |
| 1735 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1736 | return sendRequest( |
| 1737 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1738 | } |
| 1739 | |
| 1740 | /** |
| 1741 | * Posts the specified command to be executed on the main thread, |
| 1742 | * waits for the request to complete, and returns the result. |
| 1743 | * @see #sendRequestAsync |
| 1744 | */ |
| 1745 | private Object sendRequest( |
| 1746 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1747 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1748 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1749 | } |
| 1750 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1751 | MainThreadRequest request = null; |
| 1752 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1753 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1754 | } else if (phone != null) { |
| 1755 | request = new MainThreadRequest(argument, phone, workSource); |
| 1756 | } else { |
| 1757 | request = new MainThreadRequest(argument, subId, workSource); |
| 1758 | } |
| 1759 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1760 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1761 | msg.sendToTarget(); |
| 1762 | |
| 1763 | // Wait for the request to complete |
| 1764 | synchronized (request) { |
| 1765 | while (request.result == null) { |
| 1766 | try { |
| 1767 | request.wait(); |
| 1768 | } catch (InterruptedException e) { |
| 1769 | // Do nothing, go back and wait until the request is complete |
| 1770 | } |
| 1771 | } |
| 1772 | } |
| 1773 | return request.result; |
| 1774 | } |
| 1775 | |
| 1776 | /** |
| 1777 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1778 | * Posts the specified command to be executed on the main thread, and |
| 1779 | * returns immediately. |
| 1780 | * @see #sendRequest |
| 1781 | */ |
| 1782 | private void sendRequestAsync(int command) { |
| 1783 | mMainThreadHandler.sendEmptyMessage(command); |
| 1784 | } |
| 1785 | |
| 1786 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1787 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1788 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1789 | */ |
| 1790 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1791 | sendRequestAsync(command, argument, null, null); |
| 1792 | } |
| 1793 | |
| 1794 | /** |
| 1795 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1796 | * @see {@link #sendRequest(int,Object)} |
| 1797 | */ |
| 1798 | private void sendRequestAsync( |
| 1799 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1800 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1801 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1802 | msg.sendToTarget(); |
| 1803 | } |
| 1804 | |
| 1805 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1806 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1807 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1808 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1809 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1810 | synchronized (PhoneInterfaceManager.class) { |
| 1811 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1812 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1813 | } else { |
| 1814 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1815 | } |
| 1816 | return sInstance; |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1821 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1823 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1824 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1825 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1826 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1827 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1828 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1829 | mTelephonySharedPreferences = |
| 1830 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1831 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1832 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1833 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1834 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1835 | publish(); |
| 1836 | } |
| 1837 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1838 | private Phone getDefaultPhone() { |
| 1839 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1840 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1841 | } |
| 1842 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1843 | private void publish() { |
| 1844 | if (DBG) log("publish: " + this); |
| 1845 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1846 | TelephonyFrameworkInitializer |
| 1847 | .getTelephonyServiceManager() |
| 1848 | .getTelephonyServiceRegisterer() |
| 1849 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1852 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1853 | if (request.phone != null) { |
| 1854 | return request.phone; |
| 1855 | } else { |
| 1856 | return getPhoneFromSubId(request.subId); |
| 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | private Phone getPhoneFromSubId(int subId) { |
| 1861 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1862 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1863 | } |
| 1864 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1865 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1866 | Phone phone = getPhoneFromRequest(request); |
| 1867 | return phone == null ? null : |
| 1868 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1869 | } |
| 1870 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1871 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1872 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1873 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1875 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1876 | private void sendEraseModemConfig(Phone phone) { |
| 1877 | if (phone != null) { |
| 1878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1879 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1880 | final long identity = Binder.clearCallingIdentity(); |
| 1881 | try { |
| 1882 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1883 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1884 | } finally { |
| 1885 | Binder.restoreCallingIdentity(identity); |
| 1886 | } |
| 1887 | } |
| 1888 | } |
| 1889 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1890 | private boolean isImsAvailableOnDevice() { |
| 1891 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1892 | if (pm == null) { |
| 1893 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1894 | // so do not throw error and allow. |
| 1895 | return true; |
| 1896 | } |
| 1897 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1898 | } |
| 1899 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1900 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1901 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1904 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1905 | if (DBG) log("dial: " + number); |
| 1906 | // No permission check needed here: This is just a wrapper around the |
| 1907 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1908 | // the UI before it does anything. |
| 1909 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1910 | final long identity = Binder.clearCallingIdentity(); |
| 1911 | try { |
| 1912 | String url = createTelUrl(number); |
| 1913 | if (url == null) { |
| 1914 | return; |
| 1915 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1916 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1917 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1918 | PhoneConstants.State state = mCM.getState(subId); |
| 1919 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1920 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1921 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1922 | mApp.startActivity(intent); |
| 1923 | } |
| 1924 | } finally { |
| 1925 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1930 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1933 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1934 | if (DBG) log("call: " + number); |
| 1935 | |
| 1936 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1937 | // need to do a permission check since we're calling startActivity() |
| 1938 | // from the context of the phone app. |
| 1939 | enforceCallPermission(); |
| 1940 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1941 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | != AppOpsManager.MODE_ALLOWED) { |
| 1943 | return; |
| 1944 | } |
| 1945 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1946 | final long identity = Binder.clearCallingIdentity(); |
| 1947 | try { |
| 1948 | String url = createTelUrl(number); |
| 1949 | if (url == null) { |
| 1950 | return; |
| 1951 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1953 | boolean isValid = false; |
| 1954 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1955 | if (slist != null) { |
| 1956 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1957 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1958 | isValid = true; |
| 1959 | break; |
| 1960 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1961 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1962 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1963 | if (!isValid) { |
| 1964 | return; |
| 1965 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1966 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1967 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1968 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1969 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1970 | mApp.startActivity(intent); |
| 1971 | } finally { |
| 1972 | Binder.restoreCallingIdentity(identity); |
| 1973 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1976 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1977 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1978 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1979 | } |
| 1980 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1981 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1982 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1983 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1984 | } |
| 1985 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1986 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1987 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1988 | |
| 1989 | final long identity = Binder.clearCallingIdentity(); |
| 1990 | try { |
| 1991 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1992 | checkSimPin.start(); |
| 1993 | return checkSimPin.unlockSim(null, pin); |
| 1994 | } finally { |
| 1995 | Binder.restoreCallingIdentity(identity); |
| 1996 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1999 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2001 | |
| 2002 | final long identity = Binder.clearCallingIdentity(); |
| 2003 | try { |
| 2004 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2005 | checkSimPuk.start(); |
| 2006 | return checkSimPuk.unlockSim(puk, pin); |
| 2007 | } finally { |
| 2008 | Binder.restoreCallingIdentity(identity); |
| 2009 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2013 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2014 | * a synchronous one. |
| 2015 | */ |
| 2016 | private static class UnlockSim extends Thread { |
| 2017 | |
| 2018 | private final IccCard mSimCard; |
| 2019 | |
| 2020 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2021 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2022 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2023 | |
| 2024 | // For replies from SimCard interface |
| 2025 | private Handler mHandler; |
| 2026 | |
| 2027 | // For async handler to identify request type |
| 2028 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2029 | |
| 2030 | public UnlockSim(IccCard simCard) { |
| 2031 | mSimCard = simCard; |
| 2032 | } |
| 2033 | |
| 2034 | @Override |
| 2035 | public void run() { |
| 2036 | Looper.prepare(); |
| 2037 | synchronized (UnlockSim.this) { |
| 2038 | mHandler = new Handler() { |
| 2039 | @Override |
| 2040 | public void handleMessage(Message msg) { |
| 2041 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2042 | switch (msg.what) { |
| 2043 | case SUPPLY_PIN_COMPLETE: |
| 2044 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2045 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2046 | mRetryCount = msg.arg1; |
| 2047 | if (ar.exception != null) { |
| 2048 | if (ar.exception instanceof CommandException && |
| 2049 | ((CommandException)(ar.exception)).getCommandError() |
| 2050 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2051 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2052 | } //When UiccCardApp dispose,handle message and return exception |
| 2053 | else if (ar.exception instanceof CommandException && |
| 2054 | ((CommandException) (ar.exception)).getCommandError() |
| 2055 | == CommandException.Error.ABORTED) { |
| 2056 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2057 | } else { |
| 2058 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2059 | } |
| 2060 | } else { |
| 2061 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2062 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2063 | mDone = true; |
| 2064 | UnlockSim.this.notifyAll(); |
| 2065 | } |
| 2066 | break; |
| 2067 | } |
| 2068 | } |
| 2069 | }; |
| 2070 | UnlockSim.this.notifyAll(); |
| 2071 | } |
| 2072 | Looper.loop(); |
| 2073 | } |
| 2074 | |
| 2075 | /* |
| 2076 | * Use PIN or PUK to unlock SIM card |
| 2077 | * |
| 2078 | * If PUK is null, unlock SIM card with PIN |
| 2079 | * |
| 2080 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2081 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2082 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | |
| 2084 | while (mHandler == null) { |
| 2085 | try { |
| 2086 | wait(); |
| 2087 | } catch (InterruptedException e) { |
| 2088 | Thread.currentThread().interrupt(); |
| 2089 | } |
| 2090 | } |
| 2091 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2092 | |
| 2093 | if (puk == null) { |
| 2094 | mSimCard.supplyPin(pin, callback); |
| 2095 | } else { |
| 2096 | mSimCard.supplyPuk(puk, pin, callback); |
| 2097 | } |
| 2098 | |
| 2099 | while (!mDone) { |
| 2100 | try { |
| 2101 | Log.d(LOG_TAG, "wait for done"); |
| 2102 | wait(); |
| 2103 | } catch (InterruptedException e) { |
| 2104 | // Restore the interrupted status |
| 2105 | Thread.currentThread().interrupt(); |
| 2106 | } |
| 2107 | } |
| 2108 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2109 | int[] resultArray = new int[2]; |
| 2110 | resultArray[0] = mResult; |
| 2111 | resultArray[1] = mRetryCount; |
| 2112 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2113 | } |
| 2114 | } |
| 2115 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2116 | /** |
| 2117 | * This method has been removed due to privacy and stability concerns. |
| 2118 | */ |
| 2119 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2120 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2121 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2122 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2125 | @Override |
| 2126 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2127 | mApp.getSystemService(AppOpsManager.class) |
| 2128 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2129 | |
| 2130 | final int targetSdk = getTargetSdk(callingPackage); |
| 2131 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2132 | // Callers targeting S have no business invoking this method. |
| 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2137 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2138 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2139 | .setCallingPackage(callingPackage) |
| 2140 | .setCallingFeatureId(null) |
| 2141 | .setCallingPid(Binder.getCallingPid()) |
| 2142 | .setCallingUid(Binder.getCallingUid()) |
| 2143 | .setMethod("updateServiceLocation") |
| 2144 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2145 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2146 | .build()); |
| 2147 | // Apps that lack location permission have no business calling this method; |
| 2148 | // however, because no permission was declared in the public API, denials must |
| 2149 | // all be "soft". |
| 2150 | switch (locationResult) { |
| 2151 | case DENIED_HARD: /* fall through */ |
| 2152 | case DENIED_SOFT: |
| 2153 | return; |
| 2154 | } |
| 2155 | |
| 2156 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2157 | final long identity = Binder.clearCallingIdentity(); |
| 2158 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2159 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2160 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2161 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2162 | } |
| 2163 | } finally { |
| 2164 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2165 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2168 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2169 | @Override |
| 2170 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2171 | return isRadioOnWithFeature(callingPackage, null); |
| 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | @Override |
| 2176 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2177 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2178 | callingFeatureId); |
| 2179 | } |
| 2180 | |
| 2181 | @Deprecated |
| 2182 | @Override |
| 2183 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2184 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2187 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2188 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2189 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2190 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2191 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2192 | return false; |
| 2193 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2194 | |
| 2195 | final long identity = Binder.clearCallingIdentity(); |
| 2196 | try { |
| 2197 | return isRadioOnForSubscriber(subId); |
| 2198 | } finally { |
| 2199 | Binder.restoreCallingIdentity(identity); |
| 2200 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2204 | final long identity = Binder.clearCallingIdentity(); |
| 2205 | try { |
| 2206 | final Phone phone = getPhone(subId); |
| 2207 | if (phone != null) { |
| 2208 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2209 | } else { |
| 2210 | return false; |
| 2211 | } |
| 2212 | } finally { |
| 2213 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2214 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2218 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2219 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2220 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2221 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -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 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2229 | } |
| 2230 | } finally { |
| 2231 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2232 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2236 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2239 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2240 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2241 | |
| 2242 | final long identity = Binder.clearCallingIdentity(); |
| 2243 | try { |
| 2244 | final Phone phone = getPhone(subId); |
| 2245 | if (phone == null) { |
| 2246 | return false; |
| 2247 | } |
| 2248 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2249 | toggleRadioOnOffForSubscriber(subId); |
| 2250 | } |
| 2251 | return true; |
| 2252 | } finally { |
| 2253 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2254 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2256 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2257 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2258 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2259 | /* |
| 2260 | * If any of the Radios are available, it will need to be |
| 2261 | * shutdown. So return true if any Radio is available. |
| 2262 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2263 | final long identity = Binder.clearCallingIdentity(); |
| 2264 | try { |
| 2265 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2266 | Phone phone = PhoneFactory.getPhone(i); |
| 2267 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2268 | } |
| 2269 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2270 | return false; |
| 2271 | } finally { |
| 2272 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2273 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2276 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2277 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2278 | enforceModifyPermission(); |
| 2279 | |
| 2280 | final long identity = Binder.clearCallingIdentity(); |
| 2281 | try { |
| 2282 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2283 | logv("Shutting down Phone " + i); |
| 2284 | shutdownRadioUsingPhoneId(i); |
| 2285 | } |
| 2286 | } finally { |
| 2287 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2288 | } |
| 2289 | } |
| 2290 | |
| 2291 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2292 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2293 | if (phone != null && phone.isRadioAvailable()) { |
| 2294 | phone.shutdownRadio(); |
| 2295 | } |
| 2296 | } |
| 2297 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2298 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -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 defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2304 | if (defaultPhone != null) { |
| 2305 | defaultPhone.setRadioPower(turnOn); |
| 2306 | return true; |
| 2307 | } else { |
| 2308 | loge("There's no default phone."); |
| 2309 | return false; |
| 2310 | } |
| 2311 | } finally { |
| 2312 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2313 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2316 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2317 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2318 | |
| 2319 | final long identity = Binder.clearCallingIdentity(); |
| 2320 | try { |
| 2321 | final Phone phone = getPhone(subId); |
| 2322 | if (phone != null) { |
| 2323 | phone.setRadioPower(turnOn); |
| 2324 | return true; |
| 2325 | } else { |
| 2326 | return false; |
| 2327 | } |
| 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2330 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2333 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2334 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2335 | public boolean enableDataConnectivity() { |
| 2336 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2337 | |
| 2338 | final long identity = Binder.clearCallingIdentity(); |
| 2339 | try { |
| 2340 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2341 | final Phone phone = getPhone(subId); |
| 2342 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2343 | phone.getDataEnabledSettings().setDataEnabled( |
| 2344 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2345 | return true; |
| 2346 | } else { |
| 2347 | return false; |
| 2348 | } |
| 2349 | } finally { |
| 2350 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2354 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2355 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2356 | public boolean disableDataConnectivity() { |
| 2357 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2358 | |
| 2359 | final long identity = Binder.clearCallingIdentity(); |
| 2360 | try { |
| 2361 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2362 | final Phone phone = getPhone(subId); |
| 2363 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2364 | phone.getDataEnabledSettings().setDataEnabled( |
| 2365 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2366 | return true; |
| 2367 | } else { |
| 2368 | return false; |
| 2369 | } |
| 2370 | } finally { |
| 2371 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2372 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2375 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2376 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2377 | final long identity = Binder.clearCallingIdentity(); |
| 2378 | try { |
| 2379 | final Phone phone = getPhone(subId); |
| 2380 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2381 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2382 | } else { |
| 2383 | return false; |
| 2384 | } |
| 2385 | } finally { |
| 2386 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2387 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2391 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2394 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2395 | enforceCallPermission(); |
| 2396 | |
| 2397 | final long identity = Binder.clearCallingIdentity(); |
| 2398 | try { |
| 2399 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2400 | return; |
| 2401 | } |
| 2402 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2403 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2404 | } finally { |
| 2405 | Binder.restoreCallingIdentity(identity); |
| 2406 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2407 | }; |
| 2408 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2409 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2411 | |
| 2412 | final long identity = Binder.clearCallingIdentity(); |
| 2413 | try { |
| 2414 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2415 | return false; |
| 2416 | } |
| 2417 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2424 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2427 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2428 | final long identity = Binder.clearCallingIdentity(); |
| 2429 | try { |
| 2430 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2431 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2432 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2433 | } finally { |
| 2434 | Binder.restoreCallingIdentity(identity); |
| 2435 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2438 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2439 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2440 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2441 | } |
| 2442 | |
| 2443 | @Override |
| 2444 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2445 | final long identity = Binder.clearCallingIdentity(); |
| 2446 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2447 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | if (phone != null) { |
| 2449 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2450 | } else { |
| 2451 | return PhoneConstantConversions.convertDataState( |
| 2452 | PhoneConstants.DataState.DISCONNECTED); |
| 2453 | } |
| 2454 | } finally { |
| 2455 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2456 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2459 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2460 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2461 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2462 | } |
| 2463 | |
| 2464 | @Override |
| 2465 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2466 | final long identity = Binder.clearCallingIdentity(); |
| 2467 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2468 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 | if (phone != null) { |
| 2470 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2471 | } else { |
| 2472 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2473 | } |
| 2474 | } finally { |
| 2475 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2476 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2480 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2481 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2482 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2483 | |
| 2484 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2485 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2486 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2487 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2488 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2489 | .setCallingPid(Binder.getCallingPid()) |
| 2490 | .setCallingUid(Binder.getCallingUid()) |
| 2491 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2492 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2493 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2494 | .build()); |
| 2495 | switch (locationResult) { |
| 2496 | case DENIED_HARD: |
| 2497 | throw new SecurityException("Not allowed to access cell location"); |
| 2498 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2499 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2500 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2503 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | final long identity = Binder.clearCallingIdentity(); |
| 2505 | try { |
| 2506 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2507 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2508 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2509 | } finally { |
| 2510 | Binder.restoreCallingIdentity(identity); |
| 2511 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2512 | } |
| 2513 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2514 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2515 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2516 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2517 | // registered cell info, so return a NULL country instead. |
| 2518 | final long identity = Binder.clearCallingIdentity(); |
| 2519 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2520 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2521 | // Get default phone in this case. |
| 2522 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2523 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2524 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2525 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2526 | if (phone == null) return ""; |
| 2527 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2528 | if (sst == null) return ""; |
| 2529 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2530 | if (lt == null) return ""; |
| 2531 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2532 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2533 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(identity); |
| 2536 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2539 | /** |
| 2540 | * This method was removed due to potential issues caused by performing partial |
| 2541 | * updates of service state, and lack of a credible use case. |
| 2542 | * |
| 2543 | * This has the ability to break the telephony implementation by disabling notification of |
| 2544 | * changes in device connectivity. DO NOT USE THIS! |
| 2545 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2546 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2547 | public void enableLocationUpdates() { |
| 2548 | mApp.enforceCallingOrSelfPermission( |
| 2549 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2552 | /** |
| 2553 | * This method was removed due to potential issues caused by performing partial |
| 2554 | * updates of service state, and lack of a credible use case. |
| 2555 | * |
| 2556 | * This has the ability to break the telephony implementation by disabling notification of |
| 2557 | * changes in device connectivity. DO NOT USE THIS! |
| 2558 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2559 | @Override |
| 2560 | public void disableLocationUpdates() { |
| 2561 | mApp.enforceCallingOrSelfPermission( |
| 2562 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2563 | } |
| 2564 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2565 | /** |
| 2566 | * Returns the target SDK version number for a given package name. |
| 2567 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2568 | * This call MUST be invoked before clearing the calling UID. |
| 2569 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2570 | * @return target SDK if the package is found or INT_MAX. |
| 2571 | */ |
| 2572 | private int getTargetSdk(String packageName) { |
| 2573 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2574 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2575 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2576 | if (ai != null) return ai.targetSdkVersion; |
| 2577 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2578 | loge("Failed to get package info for pkg=" |
| 2579 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2580 | } |
| 2581 | return Integer.MAX_VALUE; |
| 2582 | } |
| 2583 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2584 | @Override |
| 2585 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2586 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2587 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2588 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2589 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2590 | throw new SecurityException( |
| 2591 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2592 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2593 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2594 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2595 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2596 | return null; |
| 2597 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2598 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2599 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2600 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2601 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2602 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2603 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2604 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2605 | for (CellInfo ci : info) { |
| 2606 | if (ci instanceof CellInfoGsm) { |
| 2607 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2608 | } else if (ci instanceof CellInfoWcdma) { |
| 2609 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2610 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2611 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2612 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2615 | private List<CellInfo> getCachedCellInfo() { |
| 2616 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2617 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2618 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2619 | if (info != null) cellInfos.addAll(info); |
| 2620 | } |
| 2621 | return cellInfos; |
| 2622 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2623 | |
| 2624 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2625 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2626 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2627 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2628 | |
| 2629 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2630 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2631 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2632 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2633 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2634 | .setCallingPid(Binder.getCallingPid()) |
| 2635 | .setCallingUid(Binder.getCallingUid()) |
| 2636 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2637 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2638 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2639 | .build()); |
| 2640 | switch (locationResult) { |
| 2641 | case DENIED_HARD: |
| 2642 | throw new SecurityException("Not allowed to access cell info"); |
| 2643 | case DENIED_SOFT: |
| 2644 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2647 | final int targetSdk = getTargetSdk(callingPackage); |
| 2648 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2649 | return getCachedCellInfo(); |
| 2650 | } |
| 2651 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2652 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2653 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | final long identity = Binder.clearCallingIdentity(); |
| 2655 | try { |
| 2656 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2657 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2658 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2659 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | if (info != null) cellInfos.addAll(info); |
| 2661 | } |
| 2662 | return cellInfos; |
| 2663 | } finally { |
| 2664 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2665 | } |
| 2666 | } |
| 2667 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2668 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2669 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2670 | String callingFeatureId) { |
| 2671 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2672 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2676 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2677 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2678 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2679 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2682 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2683 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2684 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2685 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2686 | |
| 2687 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2688 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2689 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2690 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2691 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2692 | .setCallingPid(Binder.getCallingPid()) |
| 2693 | .setCallingUid(Binder.getCallingUid()) |
| 2694 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2695 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2696 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2697 | .build()); |
| 2698 | switch (locationResult) { |
| 2699 | case DENIED_HARD: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2700 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2701 | // Safetynet logging for b/154934934 |
| 2702 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2703 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2704 | throw new SecurityException("Not allowed to access cell info"); |
| 2705 | case DENIED_SOFT: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2706 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2707 | // Safetynet logging for b/154934934 |
| 2708 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2709 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2710 | try { |
| 2711 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2712 | } catch (RemoteException re) { |
| 2713 | // Drop without consequences |
| 2714 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2715 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2718 | |
| 2719 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2720 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2721 | |
| 2722 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2723 | } |
| 2724 | |
| 2725 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2727 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2728 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2729 | |
| 2730 | final long identity = Binder.clearCallingIdentity(); |
| 2731 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2732 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2733 | } finally { |
| 2734 | Binder.restoreCallingIdentity(identity); |
| 2735 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2738 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2739 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2740 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2741 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2742 | return null; |
| 2743 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2744 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2745 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2746 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2747 | return null; |
| 2748 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2749 | |
| 2750 | final long identity = Binder.clearCallingIdentity(); |
| 2751 | try { |
| 2752 | return phone.getImei(); |
| 2753 | } finally { |
| 2754 | Binder.restoreCallingIdentity(identity); |
| 2755 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2759 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2760 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2761 | String tac = null; |
| 2762 | if (phone != null) { |
| 2763 | String imei = phone.getImei(); |
| 2764 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2765 | } |
| 2766 | return tac; |
| 2767 | } |
| 2768 | |
| 2769 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2770 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2771 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2772 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2773 | return null; |
| 2774 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2775 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2776 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2777 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2778 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2779 | return null; |
| 2780 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2781 | |
| 2782 | final long identity = Binder.clearCallingIdentity(); |
| 2783 | try { |
| 2784 | return phone.getMeid(); |
| 2785 | } finally { |
| 2786 | Binder.restoreCallingIdentity(identity); |
| 2787 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2791 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2792 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2793 | String manufacturerCode = null; |
| 2794 | if (phone != null) { |
| 2795 | String meid = phone.getMeid(); |
| 2796 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2797 | } |
| 2798 | return manufacturerCode; |
| 2799 | } |
| 2800 | |
| 2801 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2802 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2803 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2804 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2805 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2806 | return null; |
| 2807 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2808 | int subId = phone.getSubId(); |
| 2809 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2810 | mApp, subId, callingPackage, callingFeatureId, |
| 2811 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2812 | return null; |
| 2813 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2814 | |
| 2815 | final long identity = Binder.clearCallingIdentity(); |
| 2816 | try { |
| 2817 | return phone.getDeviceSvn(); |
| 2818 | } finally { |
| 2819 | Binder.restoreCallingIdentity(identity); |
| 2820 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2823 | @Override |
| 2824 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2825 | final long identity = Binder.clearCallingIdentity(); |
| 2826 | try { |
| 2827 | final Phone phone = getPhone(subId); |
| 2828 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2829 | } finally { |
| 2830 | Binder.restoreCallingIdentity(identity); |
| 2831 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | @Override |
| 2835 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2836 | final long identity = Binder.clearCallingIdentity(); |
| 2837 | try { |
| 2838 | final Phone phone = getPhone(subId); |
| 2839 | return phone == null ? null : phone.getCarrierName(); |
| 2840 | } finally { |
| 2841 | Binder.restoreCallingIdentity(identity); |
| 2842 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2843 | } |
| 2844 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2845 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2846 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2847 | final long identity = Binder.clearCallingIdentity(); |
| 2848 | try { |
| 2849 | final Phone phone = getPhone(subId); |
| 2850 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2851 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2852 | } finally { |
| 2853 | Binder.restoreCallingIdentity(identity); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2858 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2859 | final long identity = Binder.clearCallingIdentity(); |
| 2860 | try { |
| 2861 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2862 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2863 | } finally { |
| 2864 | Binder.restoreCallingIdentity(identity); |
| 2865 | } |
| 2866 | } |
| 2867 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2868 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2869 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2870 | if (!isSubscriptionMccMnc) { |
| 2871 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2872 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2873 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2874 | if (phone == null) { |
| 2875 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2876 | } |
| 2877 | final long identity = Binder.clearCallingIdentity(); |
| 2878 | try { |
| 2879 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2880 | } finally { |
| 2881 | Binder.restoreCallingIdentity(identity); |
| 2882 | } |
| 2883 | } |
| 2884 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2885 | // |
| 2886 | // Internal helper methods. |
| 2887 | // |
| 2888 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2889 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2891 | * |
| 2892 | * @throws SecurityException if the caller does not have the required permission |
| 2893 | */ |
| 2894 | private void enforceModifyPermission() { |
| 2895 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2896 | } |
| 2897 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2898 | /** |
| 2899 | * Make sure the caller is system. |
| 2900 | * |
| 2901 | * @throws SecurityException if the caller is not system. |
| 2902 | */ |
| 2903 | private void enforceSystemCaller() { |
| 2904 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2905 | throw new SecurityException("Caller must be system"); |
| 2906 | } |
| 2907 | } |
| 2908 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2909 | private void enforceActiveEmergencySessionPermission() { |
| 2910 | mApp.enforceCallingOrSelfPermission( |
| 2911 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2912 | } |
| 2913 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2914 | /** |
| 2915 | * Make sure the caller has the CALL_PHONE permission. |
| 2916 | * |
| 2917 | * @throws SecurityException if the caller does not have the required permission |
| 2918 | */ |
| 2919 | private void enforceCallPermission() { |
| 2920 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2921 | } |
| 2922 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2923 | private void enforceSettingsPermission() { |
| 2924 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2927 | private String createTelUrl(String number) { |
| 2928 | if (TextUtils.isEmpty(number)) { |
| 2929 | return null; |
| 2930 | } |
| 2931 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2932 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2935 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2936 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2937 | } |
| 2938 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2939 | private static void logv(String msg) { |
| 2940 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2941 | } |
| 2942 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2943 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2944 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2945 | } |
| 2946 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2947 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2948 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2949 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2952 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2953 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2954 | final long identity = Binder.clearCallingIdentity(); |
| 2955 | try { |
| 2956 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2957 | if (phone == null) { |
| 2958 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2959 | } else { |
| 2960 | return phone.getPhoneType(); |
| 2961 | } |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2964 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | /** |
| 2968 | * Returns the CDMA ERI icon index to display |
| 2969 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2970 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2971 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2972 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2973 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2974 | } |
| 2975 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2976 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2977 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2978 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2979 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2980 | mApp, subId, callingPackage, callingFeatureId, |
| 2981 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2982 | return -1; |
| 2983 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2984 | |
| 2985 | final long identity = Binder.clearCallingIdentity(); |
| 2986 | try { |
| 2987 | final Phone phone = getPhone(subId); |
| 2988 | if (phone != null) { |
| 2989 | return phone.getCdmaEriIconIndex(); |
| 2990 | } else { |
| 2991 | return -1; |
| 2992 | } |
| 2993 | } finally { |
| 2994 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2995 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | /** |
| 2999 | * Returns the CDMA ERI icon mode, |
| 3000 | * 0 - ON |
| 3001 | * 1 - FLASHING |
| 3002 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3003 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3004 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3005 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3006 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3009 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3010 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3011 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3012 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3013 | mApp, subId, callingPackage, callingFeatureId, |
| 3014 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3015 | return -1; |
| 3016 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | |
| 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | final Phone phone = getPhone(subId); |
| 3021 | if (phone != null) { |
| 3022 | return phone.getCdmaEriIconMode(); |
| 3023 | } else { |
| 3024 | return -1; |
| 3025 | } |
| 3026 | } finally { |
| 3027 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3028 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | /** |
| 3032 | * Returns the CDMA ERI text, |
| 3033 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3034 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3035 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3036 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3037 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3040 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3041 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3042 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3043 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3044 | mApp, subId, callingPackage, callingFeatureId, |
| 3045 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3046 | return null; |
| 3047 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3048 | |
| 3049 | final long identity = Binder.clearCallingIdentity(); |
| 3050 | try { |
| 3051 | final Phone phone = getPhone(subId); |
| 3052 | if (phone != null) { |
| 3053 | return phone.getCdmaEriText(); |
| 3054 | } else { |
| 3055 | return null; |
| 3056 | } |
| 3057 | } finally { |
| 3058 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3059 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3063 | * Returns the CDMA MDN. |
| 3064 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3065 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3066 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3068 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | |
| 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
| 3072 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3073 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3074 | return phone.getLine1Number(); |
| 3075 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3076 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3077 | return null; |
| 3078 | } |
| 3079 | } finally { |
| 3080 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | /** |
| 3085 | * Returns the CDMA MIN. |
| 3086 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3087 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3088 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3089 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3090 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3091 | |
| 3092 | final long identity = Binder.clearCallingIdentity(); |
| 3093 | try { |
| 3094 | final Phone phone = getPhone(subId); |
| 3095 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3096 | return phone.getCdmaMin(); |
| 3097 | } else { |
| 3098 | return null; |
| 3099 | } |
| 3100 | } finally { |
| 3101 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3102 | } |
| 3103 | } |
| 3104 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3105 | @Override |
| 3106 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3107 | INumberVerificationCallback callback, String callingPackage) { |
| 3108 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3109 | != PERMISSION_GRANTED) { |
| 3110 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3111 | } |
| 3112 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3113 | |
| 3114 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3115 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3116 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3117 | } |
| 3118 | |
| 3119 | if (range == null) { |
| 3120 | throw new NullPointerException("Range must be non-null"); |
| 3121 | } |
| 3122 | |
| 3123 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3124 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3125 | |
| 3126 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3127 | } |
| 3128 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3129 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3130 | * Returns true if CDMA provisioning needs to run. |
| 3131 | */ |
| 3132 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3133 | final long identity = Binder.clearCallingIdentity(); |
| 3134 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3135 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3136 | } finally { |
| 3137 | Binder.restoreCallingIdentity(identity); |
| 3138 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3142 | * Sets the voice mail number of a given subId. |
| 3143 | */ |
| 3144 | @Override |
| 3145 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3146 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3147 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3148 | |
| 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | try { |
| 3151 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3152 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3153 | return success; |
| 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
| 3156 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3157 | } |
| 3158 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3159 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3160 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3161 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3162 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3163 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3164 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3165 | throw new SecurityException("caller must be system dialer"); |
| 3166 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3167 | |
| 3168 | final long identity = Binder.clearCallingIdentity(); |
| 3169 | try { |
| 3170 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3171 | if (phoneAccountHandle == null) { |
| 3172 | return null; |
| 3173 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3174 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3175 | } finally { |
| 3176 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3177 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3181 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3182 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3183 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3184 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3185 | mApp, subId, callingPackage, callingFeatureId, |
| 3186 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3187 | return null; |
| 3188 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3192 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3193 | } finally { |
| 3194 | Binder.restoreCallingIdentity(identity); |
| 3195 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3199 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3200 | VisualVoicemailSmsFilterSettings settings) { |
| 3201 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3202 | |
| 3203 | final long identity = Binder.clearCallingIdentity(); |
| 3204 | try { |
| 3205 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3206 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3207 | } finally { |
| 3208 | Binder.restoreCallingIdentity(identity); |
| 3209 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3213 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3214 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3215 | |
| 3216 | final long identity = Binder.clearCallingIdentity(); |
| 3217 | try { |
| 3218 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3219 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3220 | } finally { |
| 3221 | Binder.restoreCallingIdentity(identity); |
| 3222 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3226 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3227 | String callingPackage, int subId) { |
| 3228 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3229 | |
| 3230 | final long identity = Binder.clearCallingIdentity(); |
| 3231 | try { |
| 3232 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3233 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
| 3236 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3240 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3241 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3242 | |
| 3243 | final long identity = Binder.clearCallingIdentity(); |
| 3244 | try { |
| 3245 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3246 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3247 | } finally { |
| 3248 | Binder.restoreCallingIdentity(identity); |
| 3249 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3253 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3254 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3255 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3256 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3257 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3258 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3259 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3260 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3261 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3262 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3263 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3264 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3265 | * Sets the voice activation state of a given subId. |
| 3266 | */ |
| 3267 | @Override |
| 3268 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3269 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3270 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 | |
| 3272 | final long identity = Binder.clearCallingIdentity(); |
| 3273 | try { |
| 3274 | final Phone phone = getPhone(subId); |
| 3275 | if (phone != null) { |
| 3276 | phone.setVoiceActivationState(activationState); |
| 3277 | } else { |
| 3278 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3279 | } |
| 3280 | } finally { |
| 3281 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3282 | } |
| 3283 | } |
| 3284 | |
| 3285 | /** |
| 3286 | * Sets the data activation state of a given subId. |
| 3287 | */ |
| 3288 | @Override |
| 3289 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3290 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3291 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3292 | |
| 3293 | final long identity = Binder.clearCallingIdentity(); |
| 3294 | try { |
| 3295 | final Phone phone = getPhone(subId); |
| 3296 | if (phone != null) { |
| 3297 | phone.setDataActivationState(activationState); |
| 3298 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3299 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3300 | } |
| 3301 | } finally { |
| 3302 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3303 | } |
| 3304 | } |
| 3305 | |
| 3306 | /** |
| 3307 | * Returns the voice activation state of a given subId. |
| 3308 | */ |
| 3309 | @Override |
| 3310 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3311 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3312 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3313 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | final long identity = Binder.clearCallingIdentity(); |
| 3315 | try { |
| 3316 | if (phone != null) { |
| 3317 | return phone.getVoiceActivationState(); |
| 3318 | } else { |
| 3319 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3320 | } |
| 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | /** |
| 3327 | * Returns the data activation state of a given subId. |
| 3328 | */ |
| 3329 | @Override |
| 3330 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3331 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3332 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3333 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3334 | final long identity = Binder.clearCallingIdentity(); |
| 3335 | try { |
| 3336 | if (phone != null) { |
| 3337 | return phone.getDataActivationState(); |
| 3338 | } else { |
| 3339 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3340 | } |
| 3341 | } finally { |
| 3342 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3347 | * Returns the unread count of voicemails for a subId |
| 3348 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3349 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3350 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3351 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3352 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3353 | mApp, subId, callingPackage, callingFeatureId, |
| 3354 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3355 | return 0; |
| 3356 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
| 3359 | final Phone phone = getPhone(subId); |
| 3360 | if (phone != null) { |
| 3361 | return phone.getVoiceMessageCount(); |
| 3362 | } else { |
| 3363 | return 0; |
| 3364 | } |
| 3365 | } finally { |
| 3366 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3371 | * returns true, if the device is in a state where both voice and data |
| 3372 | * are supported simultaneously. This can change based on location or network condition. |
| 3373 | */ |
| 3374 | @Override |
| 3375 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3376 | final long identity = Binder.clearCallingIdentity(); |
| 3377 | try { |
| 3378 | final Phone phone = getPhone(subId); |
| 3379 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(identity); |
| 3382 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3386 | * Send the dialer code if called from the current default dialer or the caller has |
| 3387 | * carrier privilege. |
| 3388 | * @param inputCode The dialer code to send |
| 3389 | */ |
| 3390 | @Override |
| 3391 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3392 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3393 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3394 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3395 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3396 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3397 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3398 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3399 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3400 | |
| 3401 | final long identity = Binder.clearCallingIdentity(); |
| 3402 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3403 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3404 | } finally { |
| 3405 | Binder.restoreCallingIdentity(identity); |
| 3406 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3407 | } |
| 3408 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3409 | @Override |
| 3410 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3411 | TelephonyPermissions |
| 3412 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3413 | mApp, subId, "getNetworkSelectionMode"); |
| 3414 | final long identity = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | if (!isActiveSubscription(subId)) { |
| 3417 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3418 | } |
| 3419 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3420 | } finally { |
| 3421 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3422 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3425 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3426 | public boolean isInEmergencySmsMode() { |
| 3427 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3428 | final long identity = Binder.clearCallingIdentity(); |
| 3429 | try { |
| 3430 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3431 | if (phone.isInEmergencySmsMode()) { |
| 3432 | return true; |
| 3433 | } |
| 3434 | } |
| 3435 | } finally { |
| 3436 | Binder.restoreCallingIdentity(identity); |
| 3437 | } |
| 3438 | return false; |
| 3439 | } |
| 3440 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3441 | /** |
| 3442 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3443 | * @param subId The subscription to use to check the configuration. |
| 3444 | * @param c The callback that will be used to send the result. |
| 3445 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3446 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3447 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3448 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3449 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3450 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3451 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3452 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3453 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3454 | "IMS not available on device."); |
| 3455 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3456 | final long token = Binder.clearCallingIdentity(); |
| 3457 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3458 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3459 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3460 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3461 | } catch (ImsException e) { |
| 3462 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3463 | } finally { |
| 3464 | Binder.restoreCallingIdentity(token); |
| 3465 | } |
| 3466 | } |
| 3467 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3468 | /** |
| 3469 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3470 | * @param subId The subscription to use to check the configuration. |
| 3471 | * @param c The callback that will be used to send the result. |
| 3472 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3473 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3474 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3475 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3476 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3477 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3478 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3479 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3480 | final long token = Binder.clearCallingIdentity(); |
| 3481 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3482 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3483 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3484 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3485 | } catch (ImsException e) { |
| 3486 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3487 | + "is inactive, ignoring unregister."); |
| 3488 | // If the subscription is no longer active, just return, since the callback |
| 3489 | // will already have been removed internally. |
| 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(token); |
| 3492 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3495 | /** |
| 3496 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3497 | */ |
| 3498 | @Override |
| 3499 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3500 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3501 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3502 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3503 | "IMS not available on device."); |
| 3504 | } |
| 3505 | final long token = Binder.clearCallingIdentity(); |
| 3506 | try { |
| 3507 | Phone phone = getPhone(subId); |
| 3508 | if (phone == null) { |
| 3509 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3510 | + subId + "'"); |
| 3511 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3512 | } |
| 3513 | phone.getImsRegistrationState(regState -> { |
| 3514 | try { |
| 3515 | consumer.accept((regState == null) |
| 3516 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3517 | } catch (RemoteException e) { |
| 3518 | // Ignore if the remote process is no longer available to call back. |
| 3519 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3520 | } |
| 3521 | }); |
| 3522 | } finally { |
| 3523 | Binder.restoreCallingIdentity(token); |
| 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | /** |
| 3528 | * Get the transport type for the IMS service registration state. |
| 3529 | */ |
| 3530 | @Override |
| 3531 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3532 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3533 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3534 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3535 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3536 | "IMS not available on device."); |
| 3537 | } |
| 3538 | final long token = Binder.clearCallingIdentity(); |
| 3539 | try { |
| 3540 | Phone phone = getPhone(subId); |
| 3541 | if (phone == null) { |
| 3542 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3543 | + subId + "'"); |
| 3544 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3545 | } |
| 3546 | phone.getImsRegistrationTech(regTech -> { |
| 3547 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3548 | int regTechConverted = (regTech == null) |
| 3549 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3550 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3551 | regTechConverted); |
| 3552 | try { |
| 3553 | consumer.accept(regTechConverted); |
| 3554 | } catch (RemoteException e) { |
| 3555 | // Ignore if the remote process is no longer available to call back. |
| 3556 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3557 | } |
| 3558 | }); |
| 3559 | } finally { |
| 3560 | Binder.restoreCallingIdentity(token); |
| 3561 | } |
| 3562 | } |
| 3563 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3564 | /** |
| 3565 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3566 | * @param subId The subscription to use to check the configuration. |
| 3567 | * @param c The callback that will be used to send the result. |
| 3568 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3569 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3570 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3571 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3572 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3573 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3574 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3575 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3576 | "IMS not available on device."); |
| 3577 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3578 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3579 | final long token = Binder.clearCallingIdentity(); |
| 3580 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3581 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3582 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3583 | } catch (ImsException e) { |
| 3584 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | } finally { |
| 3586 | Binder.restoreCallingIdentity(token); |
| 3587 | } |
| 3588 | } |
| 3589 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3590 | /** |
| 3591 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3592 | * @param subId The subscription to use to check the configuration. |
| 3593 | * @param c The callback that will be used to send the result. |
| 3594 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3595 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3596 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3597 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3598 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3599 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3600 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3601 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3602 | |
| 3603 | final long token = Binder.clearCallingIdentity(); |
| 3604 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3605 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3606 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3607 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3608 | } catch (ImsException e) { |
| 3609 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3610 | + "is inactive, ignoring unregister."); |
| 3611 | // If the subscription is no longer active, just return, since the callback |
| 3612 | // will already have been removed internally. |
| 3613 | } finally { |
| 3614 | Binder.restoreCallingIdentity(token); |
| 3615 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3619 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3620 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3621 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3622 | final long token = Binder.clearCallingIdentity(); |
| 3623 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3624 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3625 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3626 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3627 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3628 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3629 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3630 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3631 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3632 | } finally { |
| 3633 | Binder.restoreCallingIdentity(token); |
| 3634 | } |
| 3635 | } |
| 3636 | |
| 3637 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3638 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3639 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3640 | final long token = Binder.clearCallingIdentity(); |
| 3641 | try { |
| 3642 | Phone phone = getPhone(subId); |
| 3643 | if (phone == null) return false; |
| 3644 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3645 | } catch (com.android.ims.ImsException e) { |
| 3646 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3647 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3648 | } finally { |
| 3649 | Binder.restoreCallingIdentity(token); |
| 3650 | } |
| 3651 | } |
| 3652 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3653 | /** |
| 3654 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3655 | * subscription. |
| 3656 | * @param subId The subscription to use to check the configuration. |
| 3657 | * @param callback The callback that will be used to send the result. |
| 3658 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3659 | * @param transportType The transport type of the MmTelFeature capability. |
| 3660 | */ |
| 3661 | @Override |
| 3662 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3663 | int transportType) { |
| 3664 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3665 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3666 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3667 | "IMS not available on device."); |
| 3668 | } |
| 3669 | final long token = Binder.clearCallingIdentity(); |
| 3670 | try { |
| 3671 | int slotId = getSlotIndex(subId); |
| 3672 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3673 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3674 | + subId + "'"); |
| 3675 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3676 | } |
| 3677 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3678 | transportType, aBoolean -> { |
| 3679 | try { |
| 3680 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3681 | } catch (RemoteException e) { |
| 3682 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3683 | + "running. Ignore"); |
| 3684 | } |
| 3685 | }); |
| 3686 | } finally { |
| 3687 | Binder.restoreCallingIdentity(token); |
| 3688 | } |
| 3689 | } |
| 3690 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3691 | /** |
| 3692 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3693 | * @param subId The subscription to use to check the configuration. |
| 3694 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3695 | @Override |
| 3696 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3697 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3698 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3699 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3701 | final long token = Binder.clearCallingIdentity(); |
| 3702 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3703 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3704 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3705 | } catch (ImsException e) { |
| 3706 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3707 | } finally { |
| 3708 | Binder.restoreCallingIdentity(token); |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3713 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3715 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
| 3718 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3719 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3720 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3721 | } catch (ImsException e) { |
| 3722 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3723 | } finally { |
| 3724 | Binder.restoreCallingIdentity(identity); |
| 3725 | } |
| 3726 | } |
| 3727 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3728 | /** |
| 3729 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3730 | * @param subId The subscription to use to check the configuration. |
| 3731 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3732 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3733 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3734 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3735 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3736 | final long identity = Binder.clearCallingIdentity(); |
| 3737 | try { |
| 3738 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3739 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3740 | } catch (ImsException e) { |
| 3741 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3742 | } finally { |
| 3743 | Binder.restoreCallingIdentity(identity); |
| 3744 | } |
| 3745 | } |
| 3746 | |
| 3747 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3748 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3750 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3751 | final long identity = Binder.clearCallingIdentity(); |
| 3752 | try { |
| 3753 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3754 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3755 | } catch (ImsException e) { |
| 3756 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3757 | } finally { |
| 3758 | Binder.restoreCallingIdentity(identity); |
| 3759 | } |
| 3760 | } |
| 3761 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3762 | /** |
| 3763 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3764 | * @param subId The subscription to use to check the configuration. |
| 3765 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3766 | @Override |
| 3767 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3768 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3769 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3770 | final long identity = Binder.clearCallingIdentity(); |
| 3771 | try { |
| 3772 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3773 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3774 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3775 | } catch (ImsException e) { |
| 3776 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3777 | } finally { |
| 3778 | Binder.restoreCallingIdentity(identity); |
| 3779 | } |
| 3780 | } |
| 3781 | |
| 3782 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3783 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3785 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3786 | final long identity = Binder.clearCallingIdentity(); |
| 3787 | try { |
| 3788 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3789 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3790 | } catch (ImsException e) { |
| 3791 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3792 | } finally { |
| 3793 | Binder.restoreCallingIdentity(identity); |
| 3794 | } |
| 3795 | } |
| 3796 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3797 | /** |
| 3798 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3799 | * @param subId The subscription to use to check the configuration. |
| 3800 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3801 | @Override |
| 3802 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3803 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3804 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3805 | final long identity = Binder.clearCallingIdentity(); |
| 3806 | try { |
| 3807 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3808 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3809 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3810 | } catch (ImsException e) { |
| 3811 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3812 | } finally { |
| 3813 | Binder.restoreCallingIdentity(identity); |
| 3814 | } |
| 3815 | } |
| 3816 | |
| 3817 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3818 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3819 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3820 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3821 | final long identity = Binder.clearCallingIdentity(); |
| 3822 | try { |
| 3823 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3824 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3825 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3826 | } catch (ImsException e) { |
| 3827 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(identity); |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | @Override |
| 3834 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3835 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3836 | "setVoWiFiNonPersistent"); |
| 3837 | final long identity = Binder.clearCallingIdentity(); |
| 3838 | try { |
| 3839 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3840 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3841 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3842 | } catch (ImsException e) { |
| 3843 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3844 | } finally { |
| 3845 | Binder.restoreCallingIdentity(identity); |
| 3846 | } |
| 3847 | } |
| 3848 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3849 | /** |
| 3850 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3851 | * @param subId The subscription to use to check the configuration. |
| 3852 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3853 | @Override |
| 3854 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3855 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3856 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3857 | final long identity = Binder.clearCallingIdentity(); |
| 3858 | try { |
| 3859 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3860 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3861 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3862 | } catch (ImsException e) { |
| 3863 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3864 | } finally { |
| 3865 | Binder.restoreCallingIdentity(identity); |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | @Override |
| 3870 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3872 | "setVoWiFiModeSetting"); |
| 3873 | final long identity = Binder.clearCallingIdentity(); |
| 3874 | try { |
| 3875 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3876 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3877 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3878 | } catch (ImsException e) { |
| 3879 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3880 | } finally { |
| 3881 | Binder.restoreCallingIdentity(identity); |
| 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | @Override |
| 3886 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3887 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3888 | final long identity = Binder.clearCallingIdentity(); |
| 3889 | try { |
| 3890 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3891 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3892 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3893 | } catch (ImsException e) { |
| 3894 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3895 | } finally { |
| 3896 | Binder.restoreCallingIdentity(identity); |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | @Override |
| 3901 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3902 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3903 | "setVoWiFiRoamingModeSetting"); |
| 3904 | final long identity = Binder.clearCallingIdentity(); |
| 3905 | try { |
| 3906 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3907 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3908 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3909 | } catch (ImsException e) { |
| 3910 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3911 | } finally { |
| 3912 | Binder.restoreCallingIdentity(identity); |
| 3913 | } |
| 3914 | } |
| 3915 | |
| 3916 | @Override |
| 3917 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3919 | "setRttCapabilityEnabled"); |
| 3920 | final long identity = Binder.clearCallingIdentity(); |
| 3921 | try { |
| 3922 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3923 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3924 | } catch (ImsException e) { |
| 3925 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3926 | } finally { |
| 3927 | Binder.restoreCallingIdentity(identity); |
| 3928 | } |
| 3929 | } |
| 3930 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3931 | /** |
| 3932 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3933 | * @param subId The subscription to use to check the configuration. |
| 3934 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3935 | @Override |
| 3936 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3937 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3938 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3939 | final long identity = Binder.clearCallingIdentity(); |
| 3940 | try { |
| 3941 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3942 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3943 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3944 | } catch (ImsException e) { |
| 3945 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3946 | } finally { |
| 3947 | Binder.restoreCallingIdentity(identity); |
| 3948 | } |
| 3949 | } |
| 3950 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3951 | @Override |
| 3952 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3953 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3954 | final long identity = Binder.clearCallingIdentity(); |
| 3955 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3956 | if (!isImsAvailableOnDevice()) { |
| 3957 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3958 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3959 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 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 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3963 | } catch (ImsException e) { |
| 3964 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3965 | } finally { |
| 3966 | Binder.restoreCallingIdentity(identity); |
| 3967 | } |
| 3968 | } |
| 3969 | |
| 3970 | @Override |
| 3971 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3972 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3973 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3974 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3975 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3976 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3977 | try { |
| 3978 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3979 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3980 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3981 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3982 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3983 | + "is inactive, ignoring unregister."); |
| 3984 | // If the subscription is no longer active, just return, since the callback will already |
| 3985 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3986 | } finally { |
| 3987 | Binder.restoreCallingIdentity(identity); |
| 3988 | } |
| 3989 | } |
| 3990 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3991 | |
| 3992 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3994 | message); |
| 3995 | } |
| 3996 | |
| 3997 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3998 | boolean isMmtelCapability) { |
| 3999 | Phone phone = getPhone(subId); |
| 4000 | if (phone == null) { |
| 4001 | loge("phone instance null for subid " + subId); |
| 4002 | return false; |
| 4003 | } |
| 4004 | if (isMmtelCapability) { |
| 4005 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4006 | return false; |
| 4007 | } |
| 4008 | } else { |
| 4009 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4010 | return false; |
| 4011 | } |
| 4012 | } |
| 4013 | return true; |
| 4014 | } |
| 4015 | |
| 4016 | @Override |
| 4017 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4018 | boolean isProvisioned) { |
| 4019 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4020 | |
| 4021 | final long identity = Binder.clearCallingIdentity(); |
| 4022 | try { |
| 4023 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4024 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4025 | return; |
| 4026 | } |
| 4027 | |
| 4028 | // this capability requires provisioning, route to the correct API. |
| 4029 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4030 | switch (capability) { |
| 4031 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4032 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4033 | ims.setEabProvisioned(isProvisioned); |
| 4034 | break; |
| 4035 | default: { |
| 4036 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4037 | + "rcs capability '" + capability + "', which does not require " |
| 4038 | + "provisioning."); |
| 4039 | } |
| 4040 | } |
| 4041 | } finally { |
| 4042 | Binder.restoreCallingIdentity(identity); |
| 4043 | } |
| 4044 | |
| 4045 | } |
| 4046 | |
| 4047 | |
| 4048 | @Override |
| 4049 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4050 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4054 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4055 | return true; |
| 4056 | } |
| 4057 | |
| 4058 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4059 | switch (capability) { |
| 4060 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4061 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4062 | return ims.isEabProvisionedOnDevice(); |
| 4063 | |
| 4064 | default: { |
| 4065 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4066 | + "capability '" + capability + "', which does not require " |
| 4067 | + "provisioning."); |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(identity); |
| 4073 | } |
| 4074 | } |
| 4075 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4076 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4077 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4078 | boolean isProvisioned) { |
| 4079 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4080 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4081 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4082 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4083 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4084 | final long identity = Binder.clearCallingIdentity(); |
| 4085 | try { |
| 4086 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4087 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4088 | return; |
| 4089 | } |
| 4090 | |
| 4091 | // this capability requires provisioning, route to the correct API. |
| 4092 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4093 | switch (capability) { |
| 4094 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4095 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4096 | ims.setVolteProvisioned(isProvisioned); |
| 4097 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4098 | ims.setWfcProvisioned(isProvisioned); |
| 4099 | } |
| 4100 | break; |
| 4101 | } |
| 4102 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4103 | // There is currently no difference in VT provisioning type. |
| 4104 | ims.setVtProvisioned(isProvisioned); |
| 4105 | break; |
| 4106 | } |
| 4107 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4108 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4109 | // change the capability of the feature instead if needed. |
| 4110 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4111 | == isProvisioned) { |
| 4112 | // No change in provisioning. |
| 4113 | return; |
| 4114 | } |
| 4115 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4116 | try { |
| 4117 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4118 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4119 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4120 | + ", Exception" + e.getMessage()); |
| 4121 | } |
| 4122 | break; |
| 4123 | } |
| 4124 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4125 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4126 | + "MmTel capability '" + capability + "', which does not require " |
| 4127 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4128 | } |
| 4129 | } |
| 4130 | |
| 4131 | } finally { |
| 4132 | Binder.restoreCallingIdentity(identity); |
| 4133 | } |
| 4134 | } |
| 4135 | |
| 4136 | @Override |
| 4137 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4138 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4139 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4140 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4141 | } |
| 4142 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4143 | final long identity = Binder.clearCallingIdentity(); |
| 4144 | try { |
| 4145 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4146 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4147 | return true; |
| 4148 | } |
| 4149 | |
| 4150 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4151 | switch (capability) { |
| 4152 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4153 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4154 | return ims.isVolteProvisionedOnDevice(); |
| 4155 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4156 | return ims.isWfcProvisionedOnDevice(); |
| 4157 | } |
| 4158 | // This should never happen, since we are checking tech above to make sure it |
| 4159 | // is either LTE or IWLAN. |
| 4160 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4161 | + "capability."); |
| 4162 | } |
| 4163 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4164 | // There is currently no difference in VT provisioning type. |
| 4165 | return ims.isVtProvisionedOnDevice(); |
| 4166 | } |
| 4167 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4168 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4169 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4170 | } |
| 4171 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4172 | throw new IllegalArgumentException( |
| 4173 | "Tried to get provisioning for MmTel capability '" + capability |
| 4174 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | } finally { |
| 4179 | Binder.restoreCallingIdentity(identity); |
| 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | @Override |
| 4184 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4185 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4186 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4187 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4188 | } |
| 4189 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4190 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4191 | return (provisionedBits & capability) > 0; |
| 4192 | } |
| 4193 | |
| 4194 | @Override |
| 4195 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4196 | boolean isProvisioned) { |
| 4197 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4198 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4199 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4200 | } |
| 4201 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4202 | "setProvisioningStatusForCapability"); |
| 4203 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4204 | // If the current provisioning status for capability already matches isProvisioned, |
| 4205 | // do nothing. |
| 4206 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4207 | return; |
| 4208 | } |
| 4209 | if (isProvisioned) { |
| 4210 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4211 | } else { |
| 4212 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4213 | } |
| 4214 | } |
| 4215 | |
| 4216 | /** |
| 4217 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4218 | * technology. The bitfield should mirror the bitfield defined by |
| 4219 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4220 | */ |
| 4221 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4222 | String key = getMmTelProvisioningKey(subId, tech); |
| 4223 | // Default is no capabilities are provisioned. |
| 4224 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4225 | } |
| 4226 | |
| 4227 | /** |
| 4228 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4229 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4230 | * technology specified. |
| 4231 | * |
| 4232 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4233 | */ |
| 4234 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4235 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4236 | String key = getMmTelProvisioningKey(subId, tech); |
| 4237 | editor.putInt(key, newField); |
| 4238 | editor.commit(); |
| 4239 | } |
| 4240 | |
| 4241 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4242 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4243 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4244 | } |
| 4245 | |
| 4246 | /** |
| 4247 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4248 | * carrier associated with the subscription id. |
| 4249 | */ |
| 4250 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4251 | int capability) { |
| 4252 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4253 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4254 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4255 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4256 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4257 | false); |
| 4258 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4259 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4260 | |
| 4261 | // First check to make sure that the capability requires provisioning. |
| 4262 | switch (capability) { |
| 4263 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4264 | // intentional fallthrough |
| 4265 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4266 | if (requireVoiceVtProvisioning) { |
| 4267 | // Voice and Video requires provisioning |
| 4268 | return true; |
| 4269 | } |
| 4270 | break; |
| 4271 | } |
| 4272 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4273 | if (requireUtProvisioning) { |
| 4274 | // UT requires provisioning |
| 4275 | return true; |
| 4276 | } |
| 4277 | break; |
| 4278 | } |
| 4279 | } |
| 4280 | return false; |
| 4281 | } |
| 4282 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4283 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4284 | int capability) { |
| 4285 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4286 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4287 | |
| 4288 | boolean requireRcsProvisioning = c.getBoolean( |
| 4289 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4290 | |
| 4291 | // First check to make sure that the capability requires provisioning. |
| 4292 | switch (capability) { |
| 4293 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4294 | // intentional fallthrough |
| 4295 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4296 | if (requireRcsProvisioning) { |
| 4297 | // OPTION or PRESENCE requires provisioning |
| 4298 | return true; |
| 4299 | } |
| 4300 | break; |
| 4301 | } |
| 4302 | } |
| 4303 | return false; |
| 4304 | } |
| 4305 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4306 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4307 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4308 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4309 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4310 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4311 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4312 | final long identity = Binder.clearCallingIdentity(); |
| 4313 | try { |
| 4314 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4315 | int slotId = getSlotIndex(subId); |
| 4316 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4317 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4318 | + subId + "' for key:" + key); |
| 4319 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4320 | } |
| 4321 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4322 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4323 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4324 | + subId + "' for key:" + key); |
| 4325 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4326 | } finally { |
| 4327 | Binder.restoreCallingIdentity(identity); |
| 4328 | } |
| 4329 | } |
| 4330 | |
| 4331 | @Override |
| 4332 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4333 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4334 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4335 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4336 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4337 | final long identity = Binder.clearCallingIdentity(); |
| 4338 | try { |
| 4339 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4340 | int slotId = getSlotIndex(subId); |
| 4341 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4342 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4343 | + subId + "' for key:" + key); |
| 4344 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4345 | } |
| 4346 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4347 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4348 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4349 | + subId + "' for key:" + key); |
| 4350 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(identity); |
| 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | @Override |
| 4357 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4358 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4359 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4360 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4361 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4362 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4363 | final long identity = Binder.clearCallingIdentity(); |
| 4364 | try { |
| 4365 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4366 | int slotId = getSlotIndex(subId); |
| 4367 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4368 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4369 | + subId + "' for key:" + key); |
| 4370 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4371 | } |
| 4372 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4373 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4374 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4375 | + "' for key:" + key); |
| 4376 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4377 | } finally { |
| 4378 | Binder.restoreCallingIdentity(identity); |
| 4379 | } |
| 4380 | } |
| 4381 | |
| 4382 | @Override |
| 4383 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4384 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4385 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4386 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4387 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4388 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4389 | final long identity = Binder.clearCallingIdentity(); |
| 4390 | try { |
| 4391 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4392 | int slotId = getSlotIndex(subId); |
| 4393 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4394 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4395 | + subId + "' for key:" + key); |
| 4396 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4397 | } |
| 4398 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4399 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4400 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4401 | + "' for key:" + key); |
| 4402 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4403 | } finally { |
| 4404 | Binder.restoreCallingIdentity(identity); |
| 4405 | } |
| 4406 | } |
| 4407 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4408 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4409 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4410 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4411 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4412 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4413 | } |
| 4414 | return slotId; |
| 4415 | } |
| 4416 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4417 | private int getSlotIndex(int subId) { |
| 4418 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4419 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4420 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4421 | } |
| 4422 | return slotId; |
| 4423 | } |
| 4424 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4425 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4426 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4427 | */ |
| 4428 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4429 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4430 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4431 | final int targetSdk = getTargetSdk(callingPackage); |
| 4432 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4433 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4434 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4435 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4436 | mApp, subId, callingPackage, callingFeatureId, |
| 4437 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4438 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4439 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4440 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4441 | final long identity = Binder.clearCallingIdentity(); |
| 4442 | try { |
| 4443 | final Phone phone = getPhone(subId); |
| 4444 | if (phone != null) { |
| 4445 | return phone.getServiceState().getDataNetworkType(); |
| 4446 | } else { |
| 4447 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4448 | } |
| 4449 | } finally { |
| 4450 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4451 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4452 | } |
| 4453 | |
| 4454 | /** |
| 4455 | * Returns the data network type |
| 4456 | */ |
| 4457 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4458 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4459 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4460 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | /** |
| 4464 | * Returns the data network type for a subId |
| 4465 | */ |
| 4466 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4467 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4468 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4470 | mApp, subId, callingPackage, callingFeatureId, |
| 4471 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4472 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4473 | } |
| 4474 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4475 | final long identity = Binder.clearCallingIdentity(); |
| 4476 | try { |
| 4477 | final Phone phone = getPhone(subId); |
| 4478 | if (phone != null) { |
| 4479 | return phone.getServiceState().getDataNetworkType(); |
| 4480 | } else { |
| 4481 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4482 | } |
| 4483 | } finally { |
| 4484 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4489 | * Returns the Voice network type for a subId |
| 4490 | */ |
| 4491 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4492 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4493 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4494 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4495 | mApp, subId, callingPackage, callingFeatureId, |
| 4496 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4497 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4498 | } |
| 4499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4500 | final long identity = Binder.clearCallingIdentity(); |
| 4501 | try { |
| 4502 | final Phone phone = getPhone(subId); |
| 4503 | if (phone != null) { |
| 4504 | return phone.getServiceState().getVoiceNetworkType(); |
| 4505 | } else { |
| 4506 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4507 | } |
| 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | /** |
| 4514 | * @return true if a ICC card is present |
| 4515 | */ |
| 4516 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4517 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4518 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4519 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4523 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4524 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4525 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4526 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4527 | final long identity = Binder.clearCallingIdentity(); |
| 4528 | try { |
| 4529 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4530 | if (phone != null) { |
| 4531 | return phone.getIccCard().hasIccCard(); |
| 4532 | } else { |
| 4533 | return false; |
| 4534 | } |
| 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4537 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | /** |
| 4541 | * Return if the current radio is LTE on CDMA. This |
| 4542 | * is a tri-state return value as for a period of time |
| 4543 | * the mode may be unknown. |
| 4544 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4545 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4546 | * @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] | 4547 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4548 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4549 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4550 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4551 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4552 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4553 | } |
| 4554 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4555 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4556 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4557 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4558 | try { |
| 4559 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4560 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4561 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4562 | } |
| 4563 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4564 | final long identity = Binder.clearCallingIdentity(); |
| 4565 | try { |
| 4566 | final Phone phone = getPhone(subId); |
| 4567 | if (phone == null) { |
| 4568 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4569 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4570 | return TelephonyProperties.lte_on_cdma_device() |
| 4571 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4572 | } |
| 4573 | } finally { |
| 4574 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4575 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4576 | } |
| 4577 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4578 | /** |
| 4579 | * {@hide} |
| 4580 | * Returns Default subId, 0 in the case of single standby. |
| 4581 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4582 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4583 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4584 | } |
| 4585 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4586 | private int getSlotForDefaultSubscription() { |
| 4587 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4588 | } |
| 4589 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4590 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4591 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4592 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4593 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4594 | private boolean isActiveSubscription(int subId) { |
| 4595 | return mSubscriptionController.isActiveSubId(subId); |
| 4596 | } |
| 4597 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4598 | /** |
| 4599 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4600 | */ |
| 4601 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4602 | final long identity = Binder.clearCallingIdentity(); |
| 4603 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4604 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4605 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4606 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4607 | } finally { |
| 4608 | Binder.restoreCallingIdentity(identity); |
| 4609 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | /** |
| 4613 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4614 | */ |
| 4615 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4616 | final long identity = Binder.clearCallingIdentity(); |
| 4617 | try { |
| 4618 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4619 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4620 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(identity); |
| 4623 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4624 | } |
| 4625 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4626 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4627 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4628 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4629 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4630 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4631 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4632 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4633 | if (phoneId == -1) { |
| 4634 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4635 | + " does not correspond to an active phone"); |
| 4636 | } |
| 4637 | return PhoneFactory.getPhone(phoneId); |
| 4638 | } |
| 4639 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4640 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4641 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4642 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4643 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4644 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4645 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4646 | if (DBG) { |
| 4647 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4648 | } |
| 4649 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4650 | p2); |
| 4651 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4652 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4653 | |
| 4654 | @Override |
| 4655 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4656 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4657 | enforceModifyPermission(); |
| 4658 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4659 | if (DBG) { |
| 4660 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4661 | } |
| 4662 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4663 | callingPackage, aid, p2); |
| 4664 | } |
| 4665 | |
| 4666 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4667 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4668 | final long identity = Binder.clearCallingIdentity(); |
| 4669 | try { |
| 4670 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4671 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4672 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4673 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4674 | if (bestComponent == null |
| 4675 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4676 | loge("The calling package is not allowed to access ISD-R."); |
| 4677 | throw new SecurityException( |
| 4678 | "The calling package is not allowed to access ISD-R."); |
| 4679 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4680 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4681 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4682 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4683 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4684 | null /* workSource */); |
| 4685 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4686 | return response; |
| 4687 | } finally { |
| 4688 | Binder.restoreCallingIdentity(identity); |
| 4689 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4693 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4695 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4696 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4697 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4698 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4699 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4700 | @Override |
| 4701 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4702 | enforceModifyPermission(); |
| 4703 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4704 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4705 | channel); |
| 4706 | } |
| 4707 | |
| 4708 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4709 | final long identity = Binder.clearCallingIdentity(); |
| 4710 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4711 | if (channel < 0) { |
| 4712 | return false; |
| 4713 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4714 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4715 | null /* workSource */); |
| 4716 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4717 | return success; |
| 4718 | } finally { |
| 4719 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4720 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4724 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4725 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4726 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4727 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4728 | if (DBG) { |
| 4729 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4730 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4731 | + p3 + " data=" + data); |
| 4732 | } |
| 4733 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4734 | command, p1, p2, p3, data); |
| 4735 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4736 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4737 | @Override |
| 4738 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4739 | int command, int p1, int p2, int p3, String data) { |
| 4740 | enforceModifyPermission(); |
| 4741 | if (DBG) { |
| 4742 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4743 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4744 | + p3 + " data=" + data); |
| 4745 | } |
| 4746 | return iccTransmitApduLogicalChannelWithPermission( |
| 4747 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4748 | data); |
| 4749 | } |
| 4750 | |
| 4751 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4752 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4753 | final long identity = Binder.clearCallingIdentity(); |
| 4754 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4755 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4756 | return ""; |
| 4757 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4759 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4760 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4761 | null /* workSource */); |
| 4762 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4763 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4764 | // Append the returned status code to the end of the response payload. |
| 4765 | String s = Integer.toHexString( |
| 4766 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4767 | if (response.payload != null) { |
| 4768 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4769 | } |
| 4770 | return s; |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4773 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4774 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4775 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4776 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4777 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4778 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4779 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4780 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4782 | if (DBG) { |
| 4783 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4784 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4785 | } |
| 4786 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4787 | cla, command, p1, p2, p3, data); |
| 4788 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4789 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4790 | @Override |
| 4791 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4792 | int command, int p1, int p2, int p3, String data) { |
| 4793 | enforceModifyPermission(); |
| 4794 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4795 | if (DBG) { |
| 4796 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4797 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4798 | + " data=" + data); |
| 4799 | } |
| 4800 | |
| 4801 | return iccTransmitApduBasicChannelWithPermission( |
| 4802 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4803 | p2, p3, data); |
| 4804 | } |
| 4805 | |
| 4806 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4807 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4808 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4809 | final long identity = Binder.clearCallingIdentity(); |
| 4810 | try { |
| 4811 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4812 | && TextUtils.equals(ISDR_AID, data)) { |
| 4813 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4814 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4815 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4816 | if (bestComponent == null |
| 4817 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4818 | loge("The calling package is not allowed to select ISD-R."); |
| 4819 | throw new SecurityException( |
| 4820 | "The calling package is not allowed to select ISD-R."); |
| 4821 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4822 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4823 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4825 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4826 | null /* workSource */); |
| 4827 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
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 | // Append the returned status code to the end of the response payload. |
| 4830 | String s = Integer.toHexString( |
| 4831 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4832 | if (response.payload != null) { |
| 4833 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4834 | } |
| 4835 | return s; |
| 4836 | } finally { |
| 4837 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4838 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4842 | 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] | 4843 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4844 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4845 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4846 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4847 | final long identity = Binder.clearCallingIdentity(); |
| 4848 | try { |
| 4849 | if (DBG) { |
| 4850 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4851 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4852 | } |
| 4853 | |
| 4854 | IccIoResult response = |
| 4855 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4856 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4857 | subId); |
| 4858 | |
| 4859 | if (DBG) { |
| 4860 | log("Exchange SIM_IO [R]" + response); |
| 4861 | } |
| 4862 | |
| 4863 | byte[] result = null; |
| 4864 | int length = 2; |
| 4865 | if (response.payload != null) { |
| 4866 | length = 2 + response.payload.length; |
| 4867 | result = new byte[length]; |
| 4868 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4869 | } else { |
| 4870 | result = new byte[length]; |
| 4871 | } |
| 4872 | |
| 4873 | result[length - 1] = (byte) response.sw2; |
| 4874 | result[length - 2] = (byte) response.sw1; |
| 4875 | return result; |
| 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4878 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4879 | } |
| 4880 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4881 | /** |
| 4882 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4883 | * on a particular subscription |
| 4884 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4885 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4886 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4887 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4888 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4889 | return null; |
| 4890 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4891 | |
| 4892 | final long identity = Binder.clearCallingIdentity(); |
| 4893 | try { |
| 4894 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4895 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4896 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4897 | return null; |
| 4898 | } |
| 4899 | Object response = sendRequest( |
| 4900 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4901 | if (response instanceof String[]) { |
| 4902 | return (String[]) response; |
| 4903 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4904 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4905 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4906 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4909 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4910 | } |
| 4911 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4912 | /** |
| 4913 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4914 | * subscription. |
| 4915 | * |
| 4916 | * @param subId the id of the subscription. |
| 4917 | * @param appType the uicc app type, must be USIM or SIM. |
| 4918 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4919 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4920 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4921 | * @return number of fplmns that is successfully written to the SIM. |
| 4922 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4923 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4924 | String callingFeatureId) { |
| 4925 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4926 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4927 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4928 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4929 | } |
| 4930 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4931 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4932 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4933 | } |
| 4934 | if (fplmns == null) { |
| 4935 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4936 | } |
| 4937 | for (String fplmn : fplmns) { |
| 4938 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4939 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4940 | } |
| 4941 | } |
| 4942 | final long identity = Binder.clearCallingIdentity(); |
| 4943 | try { |
| 4944 | Object response = sendRequest( |
| 4945 | CMD_SET_FORBIDDEN_PLMNS, |
| 4946 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4947 | subId); |
| 4948 | return (int) response; |
| 4949 | } finally { |
| 4950 | Binder.restoreCallingIdentity(identity); |
| 4951 | } |
| 4952 | } |
| 4953 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4954 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4955 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4956 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4957 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4958 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4959 | final long identity = Binder.clearCallingIdentity(); |
| 4960 | try { |
| 4961 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4962 | if (response.payload == null) { |
| 4963 | return ""; |
| 4964 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4965 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4966 | // Append the returned status code to the end of the response payload. |
| 4967 | String s = Integer.toHexString( |
| 4968 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4969 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4970 | return s; |
| 4971 | } finally { |
| 4972 | Binder.restoreCallingIdentity(identity); |
| 4973 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4974 | } |
| 4975 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4976 | /** |
| 4977 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4978 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4979 | * |
| 4980 | * @param itemID the ID of the item to read |
| 4981 | * @return the NV item as a String, or null on error. |
| 4982 | */ |
| 4983 | @Override |
| 4984 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4985 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4987 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | |
| 4989 | final long identity = Binder.clearCallingIdentity(); |
| 4990 | try { |
| 4991 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4992 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4994 | return value; |
| 4995 | } finally { |
| 4996 | Binder.restoreCallingIdentity(identity); |
| 4997 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | /** |
| 5001 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5002 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5003 | * |
| 5004 | * @param itemID the ID of the item to read |
| 5005 | * @param itemValue the value to write, as a String |
| 5006 | * @return true on success; false on any failure |
| 5007 | */ |
| 5008 | @Override |
| 5009 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5010 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5012 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | |
| 5014 | final long identity = Binder.clearCallingIdentity(); |
| 5015 | try { |
| 5016 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5017 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5018 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5019 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5020 | return success; |
| 5021 | } finally { |
| 5022 | Binder.restoreCallingIdentity(identity); |
| 5023 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | /** |
| 5027 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5028 | * Used for device configuration by some CDMA operators. |
| 5029 | * |
| 5030 | * @param preferredRoamingList byte array containing the new PRL |
| 5031 | * @return true on success; false on any failure |
| 5032 | */ |
| 5033 | @Override |
| 5034 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5035 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5036 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5037 | |
| 5038 | final long identity = Binder.clearCallingIdentity(); |
| 5039 | try { |
| 5040 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5041 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5042 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5043 | return success; |
| 5044 | } finally { |
| 5045 | Binder.restoreCallingIdentity(identity); |
| 5046 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5047 | } |
| 5048 | |
| 5049 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5050 | * 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] | 5051 | * Used for device configuration by some CDMA operators. |
| 5052 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5053 | * @param slotIndex - device slot. |
| 5054 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5055 | * @return true on success; false on any failure |
| 5056 | */ |
| 5057 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5058 | public boolean resetModemConfig(int slotIndex) { |
| 5059 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5060 | if (phone != null) { |
| 5061 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5062 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5063 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5064 | final long identity = Binder.clearCallingIdentity(); |
| 5065 | try { |
| 5066 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5067 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5068 | return success; |
| 5069 | } finally { |
| 5070 | Binder.restoreCallingIdentity(identity); |
| 5071 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5072 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5073 | return false; |
| 5074 | } |
| 5075 | |
| 5076 | /** |
| 5077 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5078 | * |
| 5079 | * @param slotIndex - device slot. |
| 5080 | * |
| 5081 | * @return true on success; false on any failure |
| 5082 | */ |
| 5083 | @Override |
| 5084 | public boolean rebootModem(int slotIndex) { |
| 5085 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5086 | if (phone != null) { |
| 5087 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5088 | mApp, phone.getSubId(), "rebootModem"); |
| 5089 | |
| 5090 | final long identity = Binder.clearCallingIdentity(); |
| 5091 | try { |
| 5092 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5093 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5094 | return success; |
| 5095 | } finally { |
| 5096 | Binder.restoreCallingIdentity(identity); |
| 5097 | } |
| 5098 | } |
| 5099 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5100 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5101 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5102 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5103 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5104 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5105 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5106 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5107 | return new String[0]; |
| 5108 | } |
| 5109 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5110 | final long identity = Binder.clearCallingIdentity(); |
| 5111 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5112 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5113 | } finally { |
| 5114 | Binder.restoreCallingIdentity(identity); |
| 5115 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5116 | } |
| 5117 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5118 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5119 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5120 | * {@link #disableIms(int)}. |
| 5121 | * @param slotIndex device slot. |
| 5122 | */ |
| 5123 | public void resetIms(int slotIndex) { |
| 5124 | enforceModifyPermission(); |
| 5125 | |
| 5126 | final long identity = Binder.clearCallingIdentity(); |
| 5127 | try { |
| 5128 | if (mImsResolver == null) { |
| 5129 | // may happen if the does not support IMS. |
| 5130 | return; |
| 5131 | } |
| 5132 | mImsResolver.disableIms(slotIndex); |
| 5133 | mImsResolver.enableIms(slotIndex); |
| 5134 | } finally { |
| 5135 | Binder.restoreCallingIdentity(identity); |
| 5136 | } |
| 5137 | } |
| 5138 | |
| 5139 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5140 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5141 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5142 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5143 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5144 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5145 | |
| 5146 | final long identity = Binder.clearCallingIdentity(); |
| 5147 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5148 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5149 | // may happen if the device does not support IMS. |
| 5150 | return; |
| 5151 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5152 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | } finally { |
| 5154 | Binder.restoreCallingIdentity(identity); |
| 5155 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5156 | } |
| 5157 | |
| 5158 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5159 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5160 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5161 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5162 | public void disableIms(int slotId) { |
| 5163 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5164 | |
| 5165 | final long identity = Binder.clearCallingIdentity(); |
| 5166 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5167 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5168 | // may happen if the device does not support IMS. |
| 5169 | return; |
| 5170 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5171 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5172 | } finally { |
| 5173 | Binder.restoreCallingIdentity(identity); |
| 5174 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5175 | } |
| 5176 | |
| 5177 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5178 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5179 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5180 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5181 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5182 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5183 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5184 | |
| 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5187 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5188 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5189 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5190 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5191 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
| 5194 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5195 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5196 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5197 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5198 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5199 | @Override |
| 5200 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5201 | enforceModifyPermission(); |
| 5202 | |
| 5203 | final long identity = Binder.clearCallingIdentity(); |
| 5204 | try { |
| 5205 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5206 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5207 | } finally { |
| 5208 | Binder.restoreCallingIdentity(identity); |
| 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5213 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5214 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5215 | */ |
| 5216 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5217 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5218 | |
| 5219 | final long identity = Binder.clearCallingIdentity(); |
| 5220 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5221 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5222 | // may happen if the device does not support IMS. |
| 5223 | return null; |
| 5224 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5225 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5226 | } finally { |
| 5227 | Binder.restoreCallingIdentity(identity); |
| 5228 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5229 | } |
| 5230 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5231 | /** |
| 5232 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5233 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5234 | */ |
| 5235 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5236 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5237 | |
| 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5240 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5241 | // may happen if the device does not support IMS. |
| 5242 | return null; |
| 5243 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5244 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5245 | } finally { |
| 5246 | Binder.restoreCallingIdentity(identity); |
| 5247 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5248 | } |
| 5249 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5250 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5251 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5252 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5253 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5254 | * @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] | 5255 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5256 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5257 | * @param packageName The name of the package that the current configuration will be replaced |
| 5258 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5259 | * @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] | 5260 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5261 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5262 | int[] featureTypes, String packageName) { |
| 5263 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5264 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5265 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5266 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5267 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5268 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5271 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5272 | // may happen if the device does not support IMS. |
| 5273 | return false; |
| 5274 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5275 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5276 | for (int featureType : featureTypes) { |
| 5277 | featureConfig.put(featureType, packageName); |
| 5278 | } |
| 5279 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5280 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5281 | } finally { |
| 5282 | Binder.restoreCallingIdentity(identity); |
| 5283 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5287 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5288 | * |
| 5289 | * @param slotId The slot that the ImsService is associated with. |
| 5290 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5291 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5292 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5293 | * @return the package name of the ImsService configuration. |
| 5294 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5295 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5296 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5297 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5298 | TelephonyPermissions |
| 5299 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5300 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5301 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5302 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | final long identity = Binder.clearCallingIdentity(); |
| 5304 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5305 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5306 | // may happen if the device does not support IMS. |
| 5307 | return ""; |
| 5308 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5309 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5310 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5311 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | } finally { |
| 5313 | Binder.restoreCallingIdentity(identity); |
| 5314 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5315 | } |
| 5316 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5317 | /** |
| 5318 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5319 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5320 | * @param callback A callback with an integer containing the |
| 5321 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5322 | */ |
| 5323 | @Override |
| 5324 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5325 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5326 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5327 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5328 | "IMS not available on device."); |
| 5329 | } |
| 5330 | final long token = Binder.clearCallingIdentity(); |
| 5331 | try { |
| 5332 | int slotId = getSlotIndex(subId); |
| 5333 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5334 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5335 | + subId + "'"); |
| 5336 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5337 | } |
| 5338 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5339 | try { |
| 5340 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5341 | } catch (RemoteException e) { |
| 5342 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5343 | + "Ignore"); |
| 5344 | } |
| 5345 | }); |
| 5346 | } finally { |
| 5347 | Binder.restoreCallingIdentity(token); |
| 5348 | } |
| 5349 | } |
| 5350 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5351 | public void setImsRegistrationState(boolean registered) { |
| 5352 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | |
| 5354 | final long identity = Binder.clearCallingIdentity(); |
| 5355 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5356 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | } finally { |
| 5358 | Binder.restoreCallingIdentity(identity); |
| 5359 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5363 | * Set the network selection mode to automatic. |
| 5364 | * |
| 5365 | */ |
| 5366 | @Override |
| 5367 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5369 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5370 | |
| 5371 | final long identity = Binder.clearCallingIdentity(); |
| 5372 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5373 | if (!isActiveSubscription(subId)) { |
| 5374 | return; |
| 5375 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5377 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5378 | } finally { |
| 5379 | Binder.restoreCallingIdentity(identity); |
| 5380 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5381 | } |
| 5382 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5383 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5384 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5385 | * |
| 5386 | * @param subId the id of the subscription. |
| 5387 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5388 | * the operator to attach to. |
| 5389 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5390 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5391 | * normal network selection next time. |
| 5392 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5393 | */ |
| 5394 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5395 | public boolean setNetworkSelectionModeManual( |
| 5396 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5397 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5398 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5399 | |
| 5400 | if (!isActiveSubscription(subId)) { |
| 5401 | return false; |
| 5402 | } |
| 5403 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | final long identity = Binder.clearCallingIdentity(); |
| 5405 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5406 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5407 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5408 | if (DBG) { |
| 5409 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5410 | + " operator: " + operatorInfo); |
| 5411 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5412 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5413 | } finally { |
| 5414 | Binder.restoreCallingIdentity(identity); |
| 5415 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5416 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5417 | /** |
| 5418 | * Get the manual network selection |
| 5419 | * |
| 5420 | * @param subId the id of the subscription. |
| 5421 | * |
| 5422 | * @return the previously saved user selected PLMN |
| 5423 | */ |
| 5424 | @Override |
| 5425 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5426 | TelephonyPermissions |
| 5427 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5428 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5429 | |
| 5430 | final long identity = Binder.clearCallingIdentity(); |
| 5431 | try { |
| 5432 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5433 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | final Phone phone = getPhone(subId); |
| 5437 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5438 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5439 | } |
| 5440 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5441 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5442 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5443 | } finally { |
| 5444 | Binder.restoreCallingIdentity(identity); |
| 5445 | } |
| 5446 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5447 | |
| 5448 | /** |
| 5449 | * Scans for available networks. |
| 5450 | */ |
| 5451 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5452 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5453 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5455 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5456 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5457 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5458 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5459 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5460 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5461 | .setCallingPid(Binder.getCallingPid()) |
| 5462 | .setCallingUid(Binder.getCallingUid()) |
| 5463 | .setMethod("getCellNetworkScanResults") |
| 5464 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5465 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5466 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5467 | .build()); |
| 5468 | switch (locationResult) { |
| 5469 | case DENIED_HARD: |
| 5470 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5471 | case DENIED_SOFT: |
| 5472 | return null; |
| 5473 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5474 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5475 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5476 | try { |
| 5477 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5478 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5479 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | } finally { |
| 5481 | Binder.restoreCallingIdentity(identity); |
| 5482 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5483 | } |
| 5484 | |
| 5485 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5486 | * Get the call forwarding info, given the call forwarding reason. |
| 5487 | */ |
| 5488 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5489 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5490 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5491 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5492 | long identity = Binder.clearCallingIdentity(); |
| 5493 | try { |
| 5494 | if (DBG) { |
| 5495 | log("getCallForwarding: subId " + subId |
| 5496 | + " callForwardingReason" + callForwardingReason); |
| 5497 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5498 | |
| 5499 | Phone phone = getPhone(subId); |
| 5500 | if (phone == null) { |
| 5501 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5502 | callback.onError( |
| 5503 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5504 | } catch (RemoteException e) { |
| 5505 | // ignore |
| 5506 | } |
| 5507 | return; |
| 5508 | } |
| 5509 | |
| 5510 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5511 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5512 | @Override |
| 5513 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5514 | try { |
| 5515 | callback.onCallForwardingInfoAvailable(info); |
| 5516 | } catch (RemoteException e) { |
| 5517 | // ignore |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | @Override |
| 5522 | public void onError(int error) { |
| 5523 | try { |
| 5524 | callback.onError(error); |
| 5525 | } catch (RemoteException e) { |
| 5526 | // ignore |
| 5527 | } |
| 5528 | } |
| 5529 | }); |
| 5530 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5531 | } finally { |
| 5532 | Binder.restoreCallingIdentity(identity); |
| 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | /** |
| 5537 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5538 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5539 | */ |
| 5540 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5541 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5542 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5543 | enforceModifyPermission(); |
| 5544 | long identity = Binder.clearCallingIdentity(); |
| 5545 | try { |
| 5546 | if (DBG) { |
| 5547 | log("setCallForwarding: subId " + subId |
| 5548 | + " callForwardingInfo" + callForwardingInfo); |
| 5549 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5550 | |
| 5551 | Phone phone = getPhone(subId); |
| 5552 | if (phone == null) { |
| 5553 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5554 | callback.accept( |
| 5555 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5556 | } catch (RemoteException e) { |
| 5557 | // ignore |
| 5558 | } |
| 5559 | return; |
| 5560 | } |
| 5561 | |
| 5562 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5563 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5564 | |
| 5565 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5566 | } finally { |
| 5567 | Binder.restoreCallingIdentity(identity); |
| 5568 | } |
| 5569 | } |
| 5570 | |
| 5571 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5572 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5573 | */ |
| 5574 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5575 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5576 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5577 | long identity = Binder.clearCallingIdentity(); |
| 5578 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5579 | |
| 5580 | Phone phone = getPhone(subId); |
| 5581 | if (phone == null) { |
| 5582 | try { |
| 5583 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5584 | } catch (RemoteException e) { |
| 5585 | // ignore |
| 5586 | } |
| 5587 | return; |
| 5588 | } |
| 5589 | |
| 5590 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5591 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5592 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5593 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5594 | } finally { |
| 5595 | Binder.restoreCallingIdentity(identity); |
| 5596 | } |
| 5597 | } |
| 5598 | |
| 5599 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5600 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5601 | */ |
| 5602 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5603 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5604 | enforceModifyPermission(); |
| 5605 | long identity = Binder.clearCallingIdentity(); |
| 5606 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5607 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5608 | |
| 5609 | Phone phone = getPhone(subId); |
| 5610 | if (phone == null) { |
| 5611 | try { |
| 5612 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5613 | } catch (RemoteException e) { |
| 5614 | // ignore |
| 5615 | } |
| 5616 | return; |
| 5617 | } |
| 5618 | |
| 5619 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5620 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5621 | |
| 5622 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5623 | } finally { |
| 5624 | Binder.restoreCallingIdentity(identity); |
| 5625 | } |
| 5626 | } |
| 5627 | |
| 5628 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5629 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5630 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5631 | * @param subId id of the subscription |
| 5632 | * @param request contains the radio access networks with bands/channels to scan |
| 5633 | * @param messenger callback messenger for scan results or errors |
| 5634 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5635 | * @return the id of the requested scan which can be used to stop the scan. |
| 5636 | */ |
| 5637 | @Override |
| 5638 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5639 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5641 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5642 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5643 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5644 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5645 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5646 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5647 | .setCallingPid(Binder.getCallingPid()) |
| 5648 | .setCallingUid(Binder.getCallingUid()) |
| 5649 | .setMethod("requestNetworkScan") |
| 5650 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5651 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5652 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5653 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5654 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5655 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5656 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5657 | if (e != null) { |
| 5658 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5659 | throw e; |
| 5660 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5661 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5662 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5663 | } |
| 5664 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5665 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5666 | int callingUid = Binder.getCallingUid(); |
| 5667 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5668 | final long identity = Binder.clearCallingIdentity(); |
| 5669 | try { |
| 5670 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5671 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5672 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5673 | } finally { |
| 5674 | Binder.restoreCallingIdentity(identity); |
| 5675 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5676 | } |
| 5677 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5678 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5679 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5680 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5681 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5682 | boolean hasNetworkScanPermission = |
| 5683 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5684 | == PERMISSION_GRANTED; |
| 5685 | |
| 5686 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5687 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5688 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5689 | } |
| 5690 | |
| 5691 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5692 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5693 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5694 | return new SecurityException("Specific channels must not be" |
| 5695 | + " scanned without location access."); |
| 5696 | } |
| 5697 | } |
| 5698 | } |
| 5699 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5700 | return null; |
| 5701 | } |
| 5702 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5703 | /** |
| 5704 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5705 | * |
| 5706 | * @param subId id of the subscription |
| 5707 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5708 | */ |
| 5709 | @Override |
| 5710 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5712 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5713 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5714 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5715 | final long identity = Binder.clearCallingIdentity(); |
| 5716 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5717 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5718 | } finally { |
| 5719 | Binder.restoreCallingIdentity(identity); |
| 5720 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5724 | * Get the calculated preferred network type. |
| 5725 | * Used for debugging incorrect network type. |
| 5726 | * |
| 5727 | * @return the preferred network type, defined in RILConstants.java. |
| 5728 | */ |
| 5729 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5730 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5731 | final Phone defaultPhone = getDefaultPhone(); |
| 5732 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5733 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5734 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5735 | } |
| 5736 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5737 | final long identity = Binder.clearCallingIdentity(); |
| 5738 | try { |
| 5739 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5740 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5741 | } finally { |
| 5742 | Binder.restoreCallingIdentity(identity); |
| 5743 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5747 | * Get the preferred network type. |
| 5748 | * Used for device configuration by some CDMA operators. |
| 5749 | * |
| 5750 | * @return the preferred network type, defined in RILConstants.java. |
| 5751 | */ |
| 5752 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5753 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5754 | TelephonyPermissions |
| 5755 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5756 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5757 | |
| 5758 | final long identity = Binder.clearCallingIdentity(); |
| 5759 | try { |
| 5760 | if (DBG) log("getPreferredNetworkType"); |
| 5761 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5762 | int networkType = (result != null ? result[0] : -1); |
| 5763 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5764 | return networkType; |
| 5765 | } finally { |
| 5766 | Binder.restoreCallingIdentity(identity); |
| 5767 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | /** |
| 5771 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5772 | * |
| 5773 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5774 | * @return true on success; false on any failure. |
| 5775 | */ |
| 5776 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5777 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5778 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5779 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
| 5781 | final long identity = Binder.clearCallingIdentity(); |
| 5782 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5783 | Boolean success = (Boolean) sendRequest( |
| 5784 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5785 | |
| 5786 | if (success) { |
| 5787 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5788 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5789 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5790 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5791 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5792 | } finally { |
| 5793 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5794 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5795 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5796 | |
| 5797 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5798 | * Get the allowed network types that store in the telephony provider. |
| 5799 | * |
| 5800 | * @param subId the id of the subscription. |
| 5801 | * @return allowedNetworkTypes the allowed network types. |
| 5802 | */ |
| 5803 | @Override |
| 5804 | public long getAllowedNetworkTypes(int subId) { |
| 5805 | TelephonyPermissions |
| 5806 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5807 | mApp, subId, "getAllowedNetworkTypes"); |
| 5808 | |
| 5809 | final long identity = Binder.clearCallingIdentity(); |
| 5810 | try { |
| 5811 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5812 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5813 | } finally { |
| 5814 | Binder.restoreCallingIdentity(identity); |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | /** |
| 5819 | * Set the allowed network types. |
| 5820 | * |
| 5821 | * @param subId the id of the subscription. |
| 5822 | * @param allowedNetworkTypes the allowed network types. |
| 5823 | * @return true on success; false on any failure. |
| 5824 | */ |
| 5825 | @Override |
| 5826 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5827 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5828 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5829 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5830 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5831 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5832 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5833 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5834 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5835 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5836 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5837 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5841 | * Get the allowed network types for certain reason. |
| 5842 | * |
| 5843 | * @param subId the id of the subscription. |
| 5844 | * @param reason the reason the allowed network type change is taking place |
| 5845 | * @return the allowed network types. |
| 5846 | */ |
| 5847 | @Override |
| 5848 | public long getAllowedNetworkTypesForReason(int subId, |
| 5849 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5850 | TelephonyPermissions |
| 5851 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5852 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5853 | final long identity = Binder.clearCallingIdentity(); |
| 5854 | try { |
| 5855 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5856 | } finally { |
| 5857 | Binder.restoreCallingIdentity(identity); |
| 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 5862 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 5863 | * @param subId subscription id of the sim card |
| 5864 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 5865 | * This can be passed following states |
| 5866 | * <ol> |
| 5867 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 5868 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 5869 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 5870 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 5871 | * </ol> |
| 5872 | * @return operation result. |
| 5873 | */ |
| 5874 | @Override |
| 5875 | public int setNrDualConnectivityState(int subId, |
| 5876 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 5877 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5878 | mApp, subId, "enableNRDualConnectivity"); |
| 5879 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5880 | final long identity = Binder.clearCallingIdentity(); |
| 5881 | try { |
| 5882 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 5883 | nrDualConnectivityState, subId, |
| 5884 | workSource); |
| 5885 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 5886 | return result; |
| 5887 | } finally { |
| 5888 | Binder.restoreCallingIdentity(identity); |
| 5889 | } |
| 5890 | } |
| 5891 | |
| 5892 | /** |
| 5893 | * Is E-UTRA-NR Dual Connectivity enabled |
| 5894 | * @return true if dual connectivity is enabled else false |
| 5895 | */ |
| 5896 | @Override |
| 5897 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 5898 | TelephonyPermissions |
| 5899 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5900 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 5901 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5902 | final long identity = Binder.clearCallingIdentity(); |
| 5903 | try { |
| 5904 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 5905 | null, subId, workSource); |
| 5906 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 5907 | return isEnabled; |
| 5908 | } finally { |
| 5909 | Binder.restoreCallingIdentity(identity); |
| 5910 | } |
| 5911 | } |
| 5912 | |
| 5913 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 5914 | * get carrier bandwidth per primary and secondary carrier |
| 5915 | * @param subId subscription id of the sim card |
| 5916 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 5917 | */ |
| 5918 | @Override |
| 5919 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 5920 | TelephonyPermissions |
| 5921 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5922 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 5923 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5924 | final long identity = Binder.clearCallingIdentity(); |
| 5925 | try { |
| 5926 | CarrierBandwidth carrierBandwidth = |
| 5927 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 5928 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 5929 | return carrierBandwidth; |
| 5930 | } finally { |
| 5931 | Binder.restoreCallingIdentity(identity); |
| 5932 | } |
| 5933 | } |
| 5934 | |
| 5935 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5936 | * Get the effective allowed network types on the device. |
| 5937 | * This API will return an intersection of allowed network types for all reasons, |
| 5938 | * including the configuration done through setAllowedNetworkTypes |
| 5939 | * |
| 5940 | * @param subId the id of the subscription. |
| 5941 | * @return the allowed network types |
| 5942 | */ |
| 5943 | @Override |
| 5944 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5945 | TelephonyPermissions |
| 5946 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5947 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5948 | final long identity = Binder.clearCallingIdentity(); |
| 5949 | try { |
| 5950 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5951 | } finally { |
| 5952 | Binder.restoreCallingIdentity(identity); |
| 5953 | } |
| 5954 | } |
| 5955 | |
| 5956 | /** |
| 5957 | * Set the allowed network types of the device and |
| 5958 | * provide the reason triggering the allowed network change. |
| 5959 | * |
| 5960 | * @param subId the id of the subscription. |
| 5961 | * @param reason the reason the allowed network type change is taking place |
| 5962 | * @param allowedNetworkTypes the allowed network types. |
| 5963 | * @return true on success; false on any failure. |
| 5964 | */ |
| 5965 | @Override |
| 5966 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 5967 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 5968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5969 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 5970 | final long identity = Binder.clearCallingIdentity(); |
| 5971 | try { |
| 5972 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 5973 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5974 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5975 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5976 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 5977 | } finally { |
| 5978 | Binder.restoreCallingIdentity(identity); |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5983 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5984 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5985 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5986 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5987 | * @hide |
| 5988 | */ |
| 5989 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5990 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5991 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5993 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5995 | if (phone != null) { |
| 5996 | return phone.hasMatchedTetherApnSetting(); |
| 5997 | } else { |
| 5998 | return false; |
| 5999 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | } finally { |
| 6001 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6002 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6006 | * Enable or disable always reporting signal strength changes from radio. |
| 6007 | * |
| 6008 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6009 | */ |
| 6010 | @Override |
| 6011 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6012 | enforceModifyPermission(); |
| 6013 | enforceSystemCaller(); |
| 6014 | |
| 6015 | final long identity = Binder.clearCallingIdentity(); |
| 6016 | final Phone phone = getPhone(subId); |
| 6017 | try { |
| 6018 | if (phone != null) { |
| 6019 | if (DBG) { |
| 6020 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6021 | + " isEnable=" + isEnable); |
| 6022 | } |
| 6023 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6024 | } else { |
| 6025 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6026 | + subId); |
| 6027 | } |
| 6028 | } finally { |
| 6029 | Binder.restoreCallingIdentity(identity); |
| 6030 | } |
| 6031 | } |
| 6032 | |
| 6033 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6034 | * Get the user enabled state of Mobile Data. |
| 6035 | * |
| 6036 | * TODO: remove and use isUserDataEnabled. |
| 6037 | * This can't be removed now because some vendor codes |
| 6038 | * calls through ITelephony directly while they should |
| 6039 | * use TelephonyManager. |
| 6040 | * |
| 6041 | * @return true on enabled |
| 6042 | */ |
| 6043 | @Override |
| 6044 | public boolean getDataEnabled(int subId) { |
| 6045 | return isUserDataEnabled(subId); |
| 6046 | } |
| 6047 | |
| 6048 | /** |
| 6049 | * Get whether mobile data is enabled per user setting. |
| 6050 | * |
| 6051 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6052 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6053 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6054 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6055 | * |
| 6056 | * @return {@code true} if data is enabled else {@code false} |
| 6057 | */ |
| 6058 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6059 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6060 | try { |
| 6061 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6062 | null); |
| 6063 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6064 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6065 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | |
| 6068 | final long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
| 6070 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6071 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6072 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6073 | if (phone != null) { |
| 6074 | boolean retVal = phone.isUserDataEnabled(); |
| 6075 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6076 | return retVal; |
| 6077 | } else { |
| 6078 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6079 | return false; |
| 6080 | } |
| 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6087 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6088 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6089 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6090 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6091 | * @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] | 6092 | */ |
| 6093 | @Override |
| 6094 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6095 | try { |
| 6096 | try { |
| 6097 | mApp.enforceCallingOrSelfPermission( |
| 6098 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6099 | null); |
| 6100 | } catch (Exception e) { |
| 6101 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6102 | "isDataEnabled"); |
| 6103 | } |
| 6104 | } catch (Exception e) { |
| 6105 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6106 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | |
| 6108 | final long identity = Binder.clearCallingIdentity(); |
| 6109 | try { |
| 6110 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6111 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6112 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6113 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6114 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6116 | return retVal; |
| 6117 | } else { |
| 6118 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6119 | return false; |
| 6120 | } |
| 6121 | } finally { |
| 6122 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6123 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6124 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6125 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6126 | /** |
| 6127 | * Check if data is enabled for a specific reason |
| 6128 | * @param subId Subscription index |
| 6129 | * @param reason the reason the data enable change is taking place |
| 6130 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6131 | */ |
| 6132 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6133 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6134 | @TelephonyManager.DataEnabledReason int reason) { |
| 6135 | try { |
| 6136 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6137 | null); |
| 6138 | } catch (Exception e) { |
| 6139 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6140 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | |
| 6144 | final long identity = Binder.clearCallingIdentity(); |
| 6145 | try { |
| 6146 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6147 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6148 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6149 | + " reason=" + reason); |
| 6150 | } |
| 6151 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6152 | if (phone != null) { |
| 6153 | boolean retVal; |
| 6154 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6155 | retVal = phone.isUserDataEnabled(); |
| 6156 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6157 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6158 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6159 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6160 | return retVal; |
| 6161 | } else { |
| 6162 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6163 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6164 | + subId + " retVal=false"); |
| 6165 | } |
| 6166 | return false; |
| 6167 | } |
| 6168 | } finally { |
| 6169 | Binder.restoreCallingIdentity(identity); |
| 6170 | } |
| 6171 | } |
| 6172 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6173 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6174 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6175 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6176 | // Skip the check if it's one of these special uids |
| 6177 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6178 | } |
| 6179 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6180 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6181 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6182 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6183 | || subController == null) return privilegeFromSim; |
| 6184 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6185 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6186 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6187 | |
| 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6190 | int subId = phone.getSubId(); |
| 6191 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6192 | // A test override is in place for the privileges for this subId, so don't try to |
| 6193 | // read the subscription privileges. |
| 6194 | return privilegeFromSim; |
| 6195 | } |
| 6196 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6197 | SubscriptionManager subManager = (SubscriptionManager) |
| 6198 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6199 | for (String pkg : packages) { |
| 6200 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6201 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6202 | } |
| 6203 | } |
| 6204 | return privilegeFromSim; |
| 6205 | } finally { |
| 6206 | Binder.restoreCallingIdentity(identity); |
| 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6211 | String pkgName) { |
| 6212 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6213 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6214 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6215 | || subController == null) return privilegeFromSim; |
| 6216 | |
| 6217 | final long identity = Binder.clearCallingIdentity(); |
| 6218 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6219 | int subId = phone.getSubId(); |
| 6220 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6221 | // A test override is in place for the privileges for this subId, so don't try to |
| 6222 | // read the subscription privileges. |
| 6223 | return privilegeFromSim; |
| 6224 | } |
| 6225 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6226 | SubscriptionManager subManager = (SubscriptionManager) |
| 6227 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6228 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6229 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6230 | } finally { |
| 6231 | Binder.restoreCallingIdentity(identity); |
| 6232 | } |
| 6233 | } |
| 6234 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6235 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6236 | public int getCarrierPrivilegeStatus(int subId) { |
| 6237 | final Phone phone = getPhone(subId); |
| 6238 | if (phone == null) { |
| 6239 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6240 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6241 | } |
| 6242 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6243 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6244 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6245 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6246 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6247 | |
| 6248 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6249 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6250 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6251 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6252 | |
| 6253 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6254 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6255 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6256 | final Phone phone = getPhone(subId); |
| 6257 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6258 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6259 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6260 | } |
| 6261 | UiccProfile profile = |
| 6262 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6263 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6264 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6265 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6266 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6267 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6268 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6269 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6273 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6274 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6275 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6279 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6280 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6281 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6282 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6283 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6284 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6285 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6286 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | @Override |
| 6290 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6291 | if (TextUtils.isEmpty(pkgName)) |
| 6292 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6293 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6294 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6295 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6296 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6297 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6298 | continue; |
| 6299 | } |
| 6300 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6301 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6302 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6303 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6304 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6305 | break; |
| 6306 | } |
| 6307 | } |
| 6308 | |
| 6309 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6310 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6311 | |
| 6312 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6313 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6314 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6315 | loge("phoneId " + phoneId + " is not valid."); |
| 6316 | return null; |
| 6317 | } |
| 6318 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6319 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6320 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6321 | return null ; |
| 6322 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6323 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6324 | } |
| 6325 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6326 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6327 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6328 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6329 | List<String> privilegedPackages = new ArrayList<>(); |
| 6330 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6331 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6332 | // has UICC in that slot. |
| 6333 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6334 | if (card.hasCarrierPrivilegeRules()) { |
| 6335 | if (packages == null) { |
| 6336 | // Only check packages in user 0 for now |
| 6337 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6338 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6339 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6340 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6341 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6342 | } |
| 6343 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6344 | PackageInfo pkgInfo = packages.get(p); |
| 6345 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6346 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6347 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6348 | privilegedPackages.add(pkgInfo.packageName); |
| 6349 | } |
| 6350 | } |
| 6351 | } |
| 6352 | } |
| 6353 | return privilegedPackages; |
| 6354 | } |
| 6355 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6356 | @Override |
| 6357 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6358 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6359 | |
| 6360 | final long identity = Binder.clearCallingIdentity(); |
| 6361 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6362 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6363 | try { |
| 6364 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6365 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6366 | } |
| 6367 | } finally { |
| 6368 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6369 | } |
| 6370 | return privilegedPackages; |
| 6371 | } |
| 6372 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6373 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6374 | final Phone phone = getPhone(subId); |
| 6375 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6376 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6377 | return null; |
| 6378 | } |
| 6379 | String iccId = card.getIccId(); |
| 6380 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6381 | return null; |
| 6382 | } |
| 6383 | return iccId; |
| 6384 | } |
| 6385 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6386 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6387 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6388 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6389 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6390 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6391 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6392 | final long identity = Binder.clearCallingIdentity(); |
| 6393 | try { |
| 6394 | final String iccId = getIccId(subId); |
| 6395 | final Phone phone = getPhone(subId); |
| 6396 | if (phone == null) { |
| 6397 | return false; |
| 6398 | } |
| 6399 | final String subscriberId = phone.getSubscriberId(); |
| 6400 | |
| 6401 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6402 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6403 | + subscriberId + " to " + number); |
| 6404 | } |
| 6405 | |
| 6406 | if (TextUtils.isEmpty(iccId)) { |
| 6407 | return false; |
| 6408 | } |
| 6409 | |
| 6410 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6411 | |
| 6412 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6413 | if (alphaTag == null) { |
| 6414 | editor.remove(alphaTagPrefKey); |
| 6415 | } else { |
| 6416 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6417 | } |
| 6418 | |
| 6419 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6420 | // track all merged IMSIs based on line number |
| 6421 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6422 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6423 | if (number == null) { |
| 6424 | editor.remove(numberPrefKey); |
| 6425 | editor.remove(subscriberPrefKey); |
| 6426 | } else { |
| 6427 | editor.putString(numberPrefKey, number); |
| 6428 | editor.putString(subscriberPrefKey, subscriberId); |
| 6429 | } |
| 6430 | |
| 6431 | editor.commit(); |
| 6432 | return true; |
| 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6435 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6439 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6440 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6441 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6442 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6443 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6444 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6445 | return null; |
| 6446 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6447 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6448 | final long identity = Binder.clearCallingIdentity(); |
| 6449 | try { |
| 6450 | String iccId = getIccId(subId); |
| 6451 | if (iccId != null) { |
| 6452 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6453 | if (DBG_MERGE) { |
| 6454 | log("getLine1NumberForDisplay returning " |
| 6455 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6456 | } |
| 6457 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6458 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6459 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6460 | return null; |
| 6461 | } finally { |
| 6462 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6463 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6467 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6468 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6470 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6471 | return null; |
| 6472 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6473 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6474 | final long identity = Binder.clearCallingIdentity(); |
| 6475 | try { |
| 6476 | String iccId = getIccId(subId); |
| 6477 | if (iccId != null) { |
| 6478 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6479 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6480 | } |
| 6481 | return null; |
| 6482 | } finally { |
| 6483 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6484 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6485 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6486 | |
| 6487 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6488 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6489 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6490 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6491 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6492 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6493 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6494 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6495 | return null; |
| 6496 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6497 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6498 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6499 | // the process, where TelephonyManager was instantiated. |
| 6500 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6501 | final long identity = Binder.clearCallingIdentity(); |
| 6502 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6503 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6504 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6505 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6506 | |
| 6507 | // Figure out what subscribers are currently active |
| 6508 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6509 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6510 | // Only consider subs which match the current subId |
| 6511 | // This logic can be simplified. See b/131189269 for progress. |
| 6512 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6513 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6514 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6515 | |
| 6516 | // First pass, find a number override for an active subscriber |
| 6517 | String mergeNumber = null; |
| 6518 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6519 | for (String key : prefs.keySet()) { |
| 6520 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6521 | final String subscriberId = (String) prefs.get(key); |
| 6522 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6523 | final String iccId = key.substring( |
| 6524 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6525 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6526 | mergeNumber = (String) prefs.get(numberKey); |
| 6527 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6528 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6529 | + " for active subscriber " + subscriberId); |
| 6530 | } |
| 6531 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6532 | break; |
| 6533 | } |
| 6534 | } |
| 6535 | } |
| 6536 | } |
| 6537 | |
| 6538 | // Shortcut when no active merged subscribers |
| 6539 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6540 | return null; |
| 6541 | } |
| 6542 | |
| 6543 | // Second pass, find all subscribers under that line override |
| 6544 | final ArraySet<String> result = new ArraySet<>(); |
| 6545 | for (String key : prefs.keySet()) { |
| 6546 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6547 | final String number = (String) prefs.get(key); |
| 6548 | if (mergeNumber.equals(number)) { |
| 6549 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6550 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6551 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6552 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6553 | result.add(subscriberId); |
| 6554 | } |
| 6555 | } |
| 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6560 | Arrays.sort(resultArray); |
| 6561 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6562 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6563 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6564 | } |
| 6565 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6566 | } finally { |
| 6567 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6568 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6569 | } |
| 6570 | |
| 6571 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6572 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6573 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6574 | |
| 6575 | final long identity = Binder.clearCallingIdentity(); |
| 6576 | try { |
| 6577 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6578 | TelephonyManager.class); |
| 6579 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6580 | if (subscriberId == null) { |
| 6581 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6582 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6583 | + subId); |
| 6584 | } |
| 6585 | return null; |
| 6586 | } |
| 6587 | |
| 6588 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6589 | .getSubscriptionInfo(subId); |
| 6590 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6591 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6592 | if (groupUuid == null) { |
| 6593 | return new String[]{subscriberId}; |
| 6594 | } |
| 6595 | |
| 6596 | // Get all subscriberIds from the group. |
| 6597 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6598 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6599 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6600 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6601 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6602 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6603 | if (subscriberId != null) { |
| 6604 | mergedSubscriberIds.add(subscriberId); |
| 6605 | } |
| 6606 | } |
| 6607 | |
| 6608 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6609 | } finally { |
| 6610 | Binder.restoreCallingIdentity(identity); |
| 6611 | |
| 6612 | } |
| 6613 | } |
| 6614 | |
| 6615 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6616 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6617 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6618 | subId, "setOperatorBrandOverride"); |
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 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6624 | } finally { |
| 6625 | Binder.restoreCallingIdentity(identity); |
| 6626 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6627 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6628 | |
| 6629 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6630 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6631 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6632 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6633 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6634 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6635 | |
| 6636 | final long identity = Binder.clearCallingIdentity(); |
| 6637 | try { |
| 6638 | final Phone phone = getPhone(subId); |
| 6639 | if (phone == null) { |
| 6640 | return false; |
| 6641 | } |
| 6642 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6643 | cdmaNonRoamingList); |
| 6644 | } finally { |
| 6645 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6646 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6650 | @Deprecated |
| 6651 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6652 | enforceModifyPermission(); |
| 6653 | |
| 6654 | int returnValue = 0; |
| 6655 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6656 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6657 | if(result.exception == null) { |
| 6658 | if (result.result != null) { |
| 6659 | byte[] responseData = (byte[])(result.result); |
| 6660 | if(responseData.length > oemResp.length) { |
| 6661 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6662 | responseData.length + "bytes. Buffer Size is " + |
| 6663 | oemResp.length + "bytes."); |
| 6664 | } |
| 6665 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6666 | returnValue = responseData.length; |
| 6667 | } |
| 6668 | } else { |
| 6669 | CommandException ex = (CommandException) result.exception; |
| 6670 | returnValue = ex.getCommandError().ordinal(); |
| 6671 | if(returnValue > 0) returnValue *= -1; |
| 6672 | } |
| 6673 | } catch (RuntimeException e) { |
| 6674 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6675 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6676 | if(returnValue > 0) returnValue *= -1; |
| 6677 | } |
| 6678 | |
| 6679 | return returnValue; |
| 6680 | } |
| 6681 | |
| 6682 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6683 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6684 | try { |
| 6685 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6686 | } catch (RuntimeException e) { |
| 6687 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6688 | } |
| 6689 | } |
| 6690 | |
| 6691 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6692 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6693 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6694 | try { |
| 6695 | TelephonyPermissions |
| 6696 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6697 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6698 | } catch (SecurityException e) { |
| 6699 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6700 | throw e; |
| 6701 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6702 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6703 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6704 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6705 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | final long identity = Binder.clearCallingIdentity(); |
| 6707 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6708 | TelephonyPermissions |
| 6709 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6710 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6711 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6712 | } finally { |
| 6713 | Binder.restoreCallingIdentity(identity); |
| 6714 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6715 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6716 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6717 | |
| 6718 | @Override |
| 6719 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6720 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6721 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6722 | |
| 6723 | final long identity = Binder.clearCallingIdentity(); |
| 6724 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6725 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6726 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6727 | } finally { |
| 6728 | Binder.restoreCallingIdentity(identity); |
| 6729 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6730 | } |
| 6731 | |
| 6732 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6733 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6734 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6735 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6736 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6737 | return false; |
| 6738 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6739 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6740 | final long identity = Binder.clearCallingIdentity(); |
| 6741 | try { |
| 6742 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6743 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6744 | // In the long run, we may instead need to check if there exists a connection service |
| 6745 | // which can support video calling. |
| 6746 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6747 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6748 | return imsManager.isVtEnabledByPlatform() |
| 6749 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6750 | && imsManager.isVtEnabledByUser(); |
| 6751 | } finally { |
| 6752 | Binder.restoreCallingIdentity(identity); |
| 6753 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6754 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6755 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6756 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6757 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6758 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6760 | mApp, subId, callingPackage, callingFeatureId, |
| 6761 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6762 | return false; |
| 6763 | } |
| 6764 | |
| 6765 | final long identity = Binder.clearCallingIdentity(); |
| 6766 | try { |
| 6767 | CarrierConfigManager configManager = |
| 6768 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6769 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6771 | } finally { |
| 6772 | Binder.restoreCallingIdentity(identity); |
| 6773 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6774 | } |
| 6775 | |
| 6776 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6777 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6778 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6779 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | return false; |
| 6781 | } |
| 6782 | |
| 6783 | final long identity = Binder.clearCallingIdentity(); |
| 6784 | try { |
| 6785 | CarrierConfigManager configManager = |
| 6786 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6787 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6788 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6789 | } finally { |
| 6790 | Binder.restoreCallingIdentity(identity); |
| 6791 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6792 | } |
| 6793 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6794 | @Override |
| 6795 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6796 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6797 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6798 | } |
| 6799 | |
| 6800 | @Override |
| 6801 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6802 | final long identity = Binder.clearCallingIdentity(); |
| 6803 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6804 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6805 | } finally { |
| 6806 | Binder.restoreCallingIdentity(identity); |
| 6807 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6808 | } |
| 6809 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6810 | /** |
| 6811 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6812 | * support for the feature and device firmware support. |
| 6813 | * |
| 6814 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6815 | */ |
| 6816 | @Override |
| 6817 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6818 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6819 | final Phone phone = getPhone(subscriptionId); |
| 6820 | if (phone == null) { |
| 6821 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6822 | return false; |
| 6823 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6824 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6825 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6826 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6827 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6828 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6829 | return isCarrierSupported && isDeviceSupported; |
| 6830 | } finally { |
| 6831 | Binder.restoreCallingIdentity(identity); |
| 6832 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6833 | } |
| 6834 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6835 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6836 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6837 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6838 | * 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] | 6839 | */ |
| 6840 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | final long identity = Binder.clearCallingIdentity(); |
| 6842 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6843 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6844 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6845 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6846 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6847 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6848 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6849 | } finally { |
| 6850 | Binder.restoreCallingIdentity(identity); |
| 6851 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6852 | } |
| 6853 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6854 | @Deprecated |
| 6855 | @Override |
| 6856 | public String getDeviceId(String callingPackage) { |
| 6857 | return getDeviceIdWithFeature(callingPackage, null); |
| 6858 | } |
| 6859 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6860 | /** |
| 6861 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6862 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6863 | * |
| 6864 | * <p>Requires Permission: |
| 6865 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6866 | */ |
| 6867 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6868 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6869 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6870 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6871 | return null; |
| 6872 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6873 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6874 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6875 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6876 | return null; |
| 6877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6878 | |
| 6879 | final long identity = Binder.clearCallingIdentity(); |
| 6880 | try { |
| 6881 | return phone.getDeviceId(); |
| 6882 | } finally { |
| 6883 | Binder.restoreCallingIdentity(identity); |
| 6884 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6885 | } |
| 6886 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6887 | /** |
| 6888 | * {@hide} |
| 6889 | * Returns the IMS Registration Status on a particular subid |
| 6890 | * |
| 6891 | * @param subId |
| 6892 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6893 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6894 | Phone phone = getPhone(subId); |
| 6895 | if (phone != null) { |
| 6896 | return phone.isImsRegistered(); |
| 6897 | } else { |
| 6898 | return false; |
| 6899 | } |
| 6900 | } |
| 6901 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6902 | @Override |
| 6903 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | final long identity = Binder.clearCallingIdentity(); |
| 6905 | try { |
| 6906 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6907 | } finally { |
| 6908 | Binder.restoreCallingIdentity(identity); |
| 6909 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6910 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6911 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6912 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6913 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6914 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6915 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6916 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6917 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6918 | } |
| 6919 | final long identity = Binder.clearCallingIdentity(); |
| 6920 | try { |
| 6921 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6922 | } finally { |
| 6923 | Binder.restoreCallingIdentity(identity); |
| 6924 | } |
| 6925 | } |
| 6926 | |
| 6927 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6928 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 6929 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 6930 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6931 | final long identity = Binder.clearCallingIdentity(); |
| 6932 | try { |
| 6933 | Phone phone = getPhone(subscriptionId); |
| 6934 | if (phone == null) { |
| 6935 | return null; |
| 6936 | } |
| 6937 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6938 | } finally { |
| 6939 | Binder.restoreCallingIdentity(identity); |
| 6940 | } |
| 6941 | } |
| 6942 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6943 | /** |
| 6944 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6945 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6946 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6947 | final long identity = Binder.clearCallingIdentity(); |
| 6948 | try { |
| 6949 | Phone phone = getPhone(subId); |
| 6950 | if (phone != null) { |
| 6951 | return phone.isWifiCallingEnabled(); |
| 6952 | } else { |
| 6953 | return false; |
| 6954 | } |
| 6955 | } finally { |
| 6956 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6957 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6958 | } |
| 6959 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6960 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6961 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6962 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6963 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6964 | final long identity = Binder.clearCallingIdentity(); |
| 6965 | try { |
| 6966 | Phone phone = getPhone(subId); |
| 6967 | if (phone != null) { |
| 6968 | return phone.isVideoEnabled(); |
| 6969 | } else { |
| 6970 | return false; |
| 6971 | } |
| 6972 | } finally { |
| 6973 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6974 | } |
| 6975 | } |
| 6976 | |
| 6977 | /** |
| 6978 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6979 | * defined in {@link ImsRegistrationImplBase}. |
| 6980 | */ |
| 6981 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | final long identity = Binder.clearCallingIdentity(); |
| 6983 | try { |
| 6984 | Phone phone = getPhone(subId); |
| 6985 | if (phone != null) { |
| 6986 | return phone.getImsRegistrationTech(); |
| 6987 | } else { |
| 6988 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6989 | } |
| 6990 | } finally { |
| 6991 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6992 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6993 | } |
| 6994 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6995 | @Override |
| 6996 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6997 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6998 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6999 | return; |
| 7000 | } |
| 7001 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7002 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7003 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7004 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7005 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7006 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7007 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7008 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7009 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7010 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7011 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7012 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7013 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7014 | // There has been issues when Sms raw table somehow stores orphan |
| 7015 | // fragments. They lead to garbled message when new fragments come |
| 7016 | // in and combined with those stale ones. In case this happens again, |
| 7017 | // user can reset all network settings which will clean up this table. |
| 7018 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7019 | // Clean up IMS settings as well here. |
| 7020 | int slotId = getSlotIndex(subId); |
| 7021 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7022 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7023 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7024 | |
| 7025 | // Erase modem config if erase modem on network setting is enabled. |
| 7026 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7027 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7028 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7029 | sendEraseModemConfig(getDefaultPhone()); |
| 7030 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7031 | } finally { |
| 7032 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7033 | } |
| 7034 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7035 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7036 | private void cleanUpSmsRawTable(Context context) { |
| 7037 | ContentResolver resolver = context.getContentResolver(); |
| 7038 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7039 | resolver.delete(uri, null, null); |
| 7040 | } |
| 7041 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7042 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7043 | public String getSimLocaleForSubscriber(int subId) { |
| 7044 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7045 | final Phone phone = getPhone(subId); |
| 7046 | if (phone == null) { |
| 7047 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7048 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7049 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | final long identity = Binder.clearCallingIdentity(); |
| 7051 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7052 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7053 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7054 | if (info == null) { |
| 7055 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7056 | return null; |
| 7057 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7058 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7059 | // preferences (EF-PL and EF-LI)... |
| 7060 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7061 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7062 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7063 | if (localeFromDefaultSim != null) { |
| 7064 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7065 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7066 | + localeFromDefaultSim); |
| 7067 | return localeFromDefaultSim.toLanguageTag(); |
| 7068 | } else { |
| 7069 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7070 | } |
| 7071 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7072 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7074 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7075 | // the SIM and carrier preferences does not include a country we add the country |
| 7076 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7077 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7078 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7079 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | return mccLocale.toLanguageTag(); |
| 7081 | } |
| 7082 | |
| 7083 | if (DBG) log("No locale found - returning null"); |
| 7084 | return null; |
| 7085 | } finally { |
| 7086 | Binder.restoreCallingIdentity(identity); |
| 7087 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7088 | } |
| 7089 | |
| 7090 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7091 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7092 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7093 | } |
| 7094 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7095 | /** |
| 7096 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7097 | */ |
| 7098 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7099 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7100 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7101 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7102 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7103 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7104 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7105 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7106 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7107 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7108 | * representing the state of the modem. |
| 7109 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7110 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7111 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7112 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7113 | */ |
| 7114 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7115 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7116 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7117 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7118 | |
| 7119 | final long identity = Binder.clearCallingIdentity(); |
| 7120 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7121 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7122 | } finally { |
| 7123 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7124 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7125 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7126 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7127 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7128 | // less than total activity duration. |
| 7129 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7130 | if (info == null) { |
| 7131 | return false; |
| 7132 | } |
| 7133 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7134 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7135 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7136 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7137 | return (info.isValid() |
| 7138 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7139 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7140 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7141 | && (totalTxTimeMs <= activityDurationMs)); |
| 7142 | } |
| 7143 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7144 | /** |
| 7145 | * {@hide} |
| 7146 | * Returns the service state information on specified subscription. |
| 7147 | */ |
| 7148 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7149 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7150 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7151 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7152 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7153 | return null; |
| 7154 | } |
| 7155 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7156 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7157 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7158 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7159 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7160 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7161 | .setCallingPid(Binder.getCallingPid()) |
| 7162 | .setCallingUid(Binder.getCallingUid()) |
| 7163 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7164 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7165 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7166 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7167 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7168 | .build()); |
| 7169 | |
| 7170 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7171 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7172 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7173 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7174 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7175 | .setCallingPid(Binder.getCallingPid()) |
| 7176 | .setCallingUid(Binder.getCallingUid()) |
| 7177 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7178 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7179 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7180 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7181 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7182 | .build()); |
| 7183 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7184 | boolean hasFinePermission = |
| 7185 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7186 | boolean hasCoarsePermission = |
| 7187 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7188 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7189 | final Phone phone = getPhone(subId); |
| 7190 | if (phone == null) { |
| 7191 | return null; |
| 7192 | } |
| 7193 | |
| 7194 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7195 | .contains(callingPackage); |
| 7196 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | final long identity = Binder.clearCallingIdentity(); |
| 7198 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7199 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7200 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7201 | Rlog.d(LOG_TAG, |
| 7202 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7203 | return null; |
| 7204 | } |
| 7205 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7206 | ServiceState ss = phone.getServiceState(); |
| 7207 | |
| 7208 | // Scrub out the location info in ServiceState depending on what level of access |
| 7209 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7210 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7211 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7212 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7213 | } finally { |
| 7214 | Binder.restoreCallingIdentity(identity); |
| 7215 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7216 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7217 | |
| 7218 | /** |
| 7219 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7220 | * |
| 7221 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7222 | * voicemail ringtone. |
| 7223 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7224 | * PhoneAccount. |
| 7225 | */ |
| 7226 | @Override |
| 7227 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7228 | final long identity = Binder.clearCallingIdentity(); |
| 7229 | try { |
| 7230 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7231 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7232 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7233 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7236 | } finally { |
| 7237 | Binder.restoreCallingIdentity(identity); |
| 7238 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7239 | } |
| 7240 | |
| 7241 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7242 | * Sets the per-account voicemail ringtone. |
| 7243 | * |
| 7244 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7245 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7246 | * |
| 7247 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7248 | * voicemail ringtone. |
| 7249 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7250 | * PhoneAccount. |
| 7251 | */ |
| 7252 | @Override |
| 7253 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7254 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7255 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7256 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7257 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7258 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7260 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7261 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7262 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7263 | |
| 7264 | final long identity = Binder.clearCallingIdentity(); |
| 7265 | try { |
| 7266 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7267 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7268 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | } |
| 7270 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7271 | } finally { |
| 7272 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7273 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7274 | } |
| 7275 | |
| 7276 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7277 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7278 | * |
| 7279 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7280 | * voicemail vibration setting. |
| 7281 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7282 | */ |
| 7283 | @Override |
| 7284 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7285 | final long identity = Binder.clearCallingIdentity(); |
| 7286 | try { |
| 7287 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7288 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7289 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7290 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7291 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7292 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7293 | } finally { |
| 7294 | Binder.restoreCallingIdentity(identity); |
| 7295 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7296 | } |
| 7297 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7298 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7299 | * Sets the per-account voicemail vibration. |
| 7300 | * |
| 7301 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7302 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7303 | * |
| 7304 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7305 | * voicemail vibration setting. |
| 7306 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7307 | * specific PhoneAccount. |
| 7308 | */ |
| 7309 | @Override |
| 7310 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7311 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7312 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7313 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7314 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7315 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7317 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7318 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7319 | } |
| 7320 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7321 | final long identity = Binder.clearCallingIdentity(); |
| 7322 | try { |
| 7323 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7324 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7325 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7326 | } |
| 7327 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7328 | } finally { |
| 7329 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7330 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7331 | } |
| 7332 | |
| 7333 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7334 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7335 | * |
| 7336 | * @throws SecurityException if the caller does not have the required permission |
| 7337 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7338 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7339 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7340 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7341 | } |
| 7342 | |
| 7343 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7344 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7345 | * permission. |
| 7346 | * |
| 7347 | * @throws SecurityException if the caller does not have the required permission |
| 7348 | */ |
| 7349 | private void enforceSendSmsPermission() { |
| 7350 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7351 | } |
| 7352 | |
| 7353 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7354 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7355 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7356 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7357 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7358 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7359 | final long identity = Binder.clearCallingIdentity(); |
| 7360 | try { |
| 7361 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7362 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7363 | if (componentName == null) { |
| 7364 | throw new SecurityException( |
| 7365 | "Caller not current active visual voicemail package[null]"); |
| 7366 | } |
| 7367 | String vvmPackage = componentName.getPackageName(); |
| 7368 | if (!callingPackage.equals(vvmPackage)) { |
| 7369 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7370 | + vvmPackage + "]"); |
| 7371 | } |
| 7372 | } finally { |
| 7373 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7374 | } |
| 7375 | } |
| 7376 | |
| 7377 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7378 | * Return the application ID for the app type. |
| 7379 | * |
| 7380 | * @param subId the subscription ID that this request applies to. |
| 7381 | * @param appType the uicc app type. |
| 7382 | * @return Application ID for specificied app type, or null if no uicc. |
| 7383 | */ |
| 7384 | @Override |
| 7385 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7386 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7387 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | |
| 7389 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7390 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7391 | if (phone == null) { |
| 7392 | return null; |
| 7393 | } |
| 7394 | String aid = null; |
| 7395 | try { |
| 7396 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7397 | .getApplicationByType(appType).getAid(); |
| 7398 | } catch (Exception e) { |
| 7399 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7400 | } |
| 7401 | return aid; |
| 7402 | } finally { |
| 7403 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7404 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7405 | } |
| 7406 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7407 | /** |
| 7408 | * Return the Electronic Serial Number. |
| 7409 | * |
| 7410 | * @param subId the subscription ID that this request applies to. |
| 7411 | * @return ESN or null if error. |
| 7412 | */ |
| 7413 | @Override |
| 7414 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7415 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7416 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7417 | |
| 7418 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7419 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7420 | if (phone == null) { |
| 7421 | return null; |
| 7422 | } |
| 7423 | String esn = null; |
| 7424 | try { |
| 7425 | esn = phone.getEsn(); |
| 7426 | } catch (Exception e) { |
| 7427 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7428 | } |
| 7429 | return esn; |
| 7430 | } finally { |
| 7431 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7432 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7433 | } |
| 7434 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7435 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7436 | * Return the Preferred Roaming List Version. |
| 7437 | * |
| 7438 | * @param subId the subscription ID that this request applies to. |
| 7439 | * @return PRLVersion or null if error. |
| 7440 | */ |
| 7441 | @Override |
| 7442 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7443 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7444 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | |
| 7446 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7447 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7448 | if (phone == null) { |
| 7449 | return null; |
| 7450 | } |
| 7451 | String cdmaPrlVersion = null; |
| 7452 | try { |
| 7453 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7454 | } catch (Exception e) { |
| 7455 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7456 | } |
| 7457 | return cdmaPrlVersion; |
| 7458 | } finally { |
| 7459 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7460 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7461 | } |
| 7462 | |
| 7463 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7464 | * Get snapshot of Telephony histograms |
| 7465 | * @return List of Telephony histograms |
| 7466 | * @hide |
| 7467 | */ |
| 7468 | @Override |
| 7469 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7470 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7471 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7472 | |
| 7473 | final long identity = Binder.clearCallingIdentity(); |
| 7474 | try { |
| 7475 | return RIL.getTelephonyRILTimingHistograms(); |
| 7476 | } finally { |
| 7477 | Binder.restoreCallingIdentity(identity); |
| 7478 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7479 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7480 | |
| 7481 | /** |
| 7482 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7483 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7484 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7485 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7486 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7487 | * @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] | 7488 | */ |
| 7489 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7490 | @TelephonyManager.SetCarrierRestrictionResult |
| 7491 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7492 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7493 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7494 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7495 | if (carrierRestrictionRules == null) { |
| 7496 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7497 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7498 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7499 | final long identity = Binder.clearCallingIdentity(); |
| 7500 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7501 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7502 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7503 | } finally { |
| 7504 | Binder.restoreCallingIdentity(identity); |
| 7505 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7506 | } |
| 7507 | |
| 7508 | /** |
| 7509 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7510 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7511 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7512 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7513 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7514 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7515 | */ |
| 7516 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7517 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7518 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7519 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7520 | |
| 7521 | final long identity = Binder.clearCallingIdentity(); |
| 7522 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7523 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7524 | if (response instanceof CarrierRestrictionRules) { |
| 7525 | return (CarrierRestrictionRules) response; |
| 7526 | } |
| 7527 | // Response is an Exception of some kind, |
| 7528 | // which is signalled to the user as a NULL retval |
| 7529 | return null; |
| 7530 | } catch (Exception e) { |
| 7531 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7532 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7533 | } finally { |
| 7534 | Binder.restoreCallingIdentity(identity); |
| 7535 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7536 | } |
| 7537 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7538 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7539 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7540 | * @param subId the subscription ID that this action applies to. |
| 7541 | * @param enabled control enable or disable radio. |
| 7542 | * {@hide} |
| 7543 | */ |
| 7544 | @Override |
| 7545 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7546 | enforceModifyPermission(); |
| 7547 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | |
| 7549 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7550 | if (phone == null) { |
| 7551 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7552 | return; |
| 7553 | } |
| 7554 | try { |
| 7555 | phone.carrierActionSetRadioEnabled(enabled); |
| 7556 | } catch (Exception e) { |
| 7557 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7558 | } finally { |
| 7559 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7560 | } |
| 7561 | } |
| 7562 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7563 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7564 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7565 | * network status based on which carrier apps could apply actions accordingly, |
| 7566 | * enable/disable default url handler for example. |
| 7567 | * |
| 7568 | * @param subId the subscription ID that this action applies to. |
| 7569 | * @param report control start/stop reporting the default network status. |
| 7570 | * {@hide} |
| 7571 | */ |
| 7572 | @Override |
| 7573 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7574 | enforceModifyPermission(); |
| 7575 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7576 | |
| 7577 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7578 | if (phone == null) { |
| 7579 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7580 | return; |
| 7581 | } |
| 7582 | try { |
| 7583 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7584 | } catch (Exception e) { |
| 7585 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7586 | } finally { |
| 7587 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7592 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7593 | * @param subId the subscription ID that this action applies to. |
| 7594 | * {@hide} |
| 7595 | */ |
| 7596 | @Override |
| 7597 | public void carrierActionResetAll(int subId) { |
| 7598 | enforceModifyPermission(); |
| 7599 | final Phone phone = getPhone(subId); |
| 7600 | if (phone == null) { |
| 7601 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7602 | return; |
| 7603 | } |
| 7604 | try { |
| 7605 | phone.carrierActionResetAll(); |
| 7606 | } catch (Exception e) { |
| 7607 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7608 | } |
| 7609 | } |
| 7610 | |
| 7611 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7612 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7613 | * bug report is being generated. |
| 7614 | */ |
| 7615 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7616 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7617 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7618 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7619 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7620 | + Binder.getCallingPid() |
| 7621 | + ", uid=" + Binder.getCallingUid() |
| 7622 | + "without permission " |
| 7623 | + android.Manifest.permission.DUMP); |
| 7624 | return; |
| 7625 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7626 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7627 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7628 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7629 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7630 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7631 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7632 | @NonNull String[] args) { |
| 7633 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7634 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7635 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7636 | } |
| 7637 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7638 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7639 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7640 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7641 | * @param reason the reason the data enable change is taking place |
| 7642 | * @param enabled True if enabling the data, otherwise disabling. |
| 7643 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7644 | */ |
| 7645 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7646 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7647 | boolean enabled) { |
| 7648 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7649 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7650 | try { |
| 7651 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7652 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7653 | } catch (SecurityException se) { |
| 7654 | enforceModifyPermission(); |
| 7655 | } |
| 7656 | } else { |
| 7657 | enforceModifyPermission(); |
| 7658 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7659 | |
| 7660 | final long identity = Binder.clearCallingIdentity(); |
| 7661 | try { |
| 7662 | Phone phone = getPhone(subId); |
| 7663 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7664 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7665 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7666 | } else { |
| 7667 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7668 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7669 | } |
| 7670 | } finally { |
| 7671 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7672 | } |
| 7673 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7674 | |
| 7675 | /** |
| 7676 | * Get Client request stats |
| 7677 | * @return List of Client Request Stats |
| 7678 | * @hide |
| 7679 | */ |
| 7680 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7681 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7682 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7683 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7684 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7685 | return null; |
| 7686 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7687 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7688 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7689 | final long identity = Binder.clearCallingIdentity(); |
| 7690 | try { |
| 7691 | if (phone != null) { |
| 7692 | return phone.getClientRequestStats(); |
| 7693 | } |
| 7694 | |
| 7695 | return null; |
| 7696 | } finally { |
| 7697 | Binder.restoreCallingIdentity(identity); |
| 7698 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7699 | } |
| 7700 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7701 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7702 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7703 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7704 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7705 | |
| 7706 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7707 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7708 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7709 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7710 | * @param state State of SIM (power down, power up, pass through) |
| 7711 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7712 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7713 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7714 | * |
| 7715 | **/ |
| 7716 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7717 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7718 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7719 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7720 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7721 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7722 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7723 | final long identity = Binder.clearCallingIdentity(); |
| 7724 | try { |
| 7725 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7726 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7727 | } |
| 7728 | } finally { |
| 7729 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7730 | } |
| 7731 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7732 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7733 | private boolean isUssdApiAllowed(int subId) { |
| 7734 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7735 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7736 | if (configManager == null) { |
| 7737 | return false; |
| 7738 | } |
| 7739 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7740 | if (pb == null) { |
| 7741 | return false; |
| 7742 | } |
| 7743 | return pb.getBoolean( |
| 7744 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7745 | } |
| 7746 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7747 | /** |
| 7748 | * Check if phone is in emergency callback mode |
| 7749 | * @return true if phone is in emergency callback mode |
| 7750 | * @param subId sub id |
| 7751 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7752 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7753 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7754 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7755 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7756 | |
| 7757 | final long identity = Binder.clearCallingIdentity(); |
| 7758 | try { |
| 7759 | if (phone != null) { |
| 7760 | return phone.isInEcm(); |
| 7761 | } else { |
| 7762 | return false; |
| 7763 | } |
| 7764 | } finally { |
| 7765 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7766 | } |
| 7767 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7768 | |
| 7769 | /** |
| 7770 | * Get the current signal strength information for the given subscription. |
| 7771 | * Because this information is not updated when the device is in a low power state |
| 7772 | * it should not be relied-upon to be current. |
| 7773 | * @param subId Subscription index |
| 7774 | * @return the most recent cached signal strength info from the modem |
| 7775 | */ |
| 7776 | @Override |
| 7777 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7778 | final long identity = Binder.clearCallingIdentity(); |
| 7779 | try { |
| 7780 | Phone p = getPhone(subId); |
| 7781 | if (p == null) { |
| 7782 | return null; |
| 7783 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7784 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7785 | return p.getSignalStrength(); |
| 7786 | } finally { |
| 7787 | Binder.restoreCallingIdentity(identity); |
| 7788 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7789 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7790 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7791 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7792 | * Get the current modem radio state for the given slot. |
| 7793 | * @param slotIndex slot index. |
| 7794 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7795 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7796 | * @return the current radio power state from the modem |
| 7797 | */ |
| 7798 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7799 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7800 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7801 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7802 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7803 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7804 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7805 | } |
| 7806 | |
| 7807 | final long identity = Binder.clearCallingIdentity(); |
| 7808 | try { |
| 7809 | return phone.getRadioPowerState(); |
| 7810 | } finally { |
| 7811 | Binder.restoreCallingIdentity(identity); |
| 7812 | } |
| 7813 | } |
| 7814 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7815 | } |
| 7816 | |
| 7817 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7818 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7819 | * |
| 7820 | * <p>Requires one of the following permissions: |
| 7821 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7822 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7823 | * privileges. |
| 7824 | * |
| 7825 | * @param subId subscription id |
| 7826 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7827 | * {@code false}. |
| 7828 | */ |
| 7829 | @Override |
| 7830 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7831 | try { |
| 7832 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7833 | null); |
| 7834 | } catch (Exception e) { |
| 7835 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7836 | mApp, subId, "isDataRoamingEnabled"); |
| 7837 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7838 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7839 | boolean isEnabled = false; |
| 7840 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7841 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7842 | Phone phone = getPhone(subId); |
| 7843 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7844 | } finally { |
| 7845 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7846 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7847 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7848 | } |
| 7849 | |
| 7850 | |
| 7851 | /** |
| 7852 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7853 | * |
| 7854 | * <p> Requires permission: |
| 7855 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7856 | * privileges. |
| 7857 | * |
| 7858 | * @param subId subscription id |
| 7859 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7860 | */ |
| 7861 | @Override |
| 7862 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7864 | mApp, subId, "setDataRoamingEnabled"); |
| 7865 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7866 | final long identity = Binder.clearCallingIdentity(); |
| 7867 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7868 | Phone phone = getPhone(subId); |
| 7869 | if (phone != null) { |
| 7870 | phone.setDataRoamingEnabled(isEnabled); |
| 7871 | } |
| 7872 | } finally { |
| 7873 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7874 | } |
| 7875 | } |
| 7876 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7877 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7878 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7879 | TelephonyPermissions |
| 7880 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7881 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7882 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7883 | boolean isAllowed = true; |
| 7884 | final long identity = Binder.clearCallingIdentity(); |
| 7885 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7886 | Phone phone = getPhone(subId); |
| 7887 | if (phone != null) { |
| 7888 | isAllowed = phone.isCspPlmnEnabled(); |
| 7889 | } |
| 7890 | } finally { |
| 7891 | Binder.restoreCallingIdentity(identity); |
| 7892 | } |
| 7893 | return isAllowed; |
| 7894 | } |
| 7895 | |
| 7896 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7897 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7898 | // Verify that tha callingPackage belongs to the calling UID |
| 7899 | mApp.getSystemService(AppOpsManager.class) |
| 7900 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7901 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7902 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7903 | try { |
| 7904 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7905 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7906 | } catch (SecurityException e) { |
| 7907 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7908 | // has carrier privileges on an active UICC |
| 7909 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7910 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7911 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7912 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7913 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7914 | |
| 7915 | final long identity = Binder.clearCallingIdentity(); |
| 7916 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7917 | UiccController uiccController = UiccController.getInstance(); |
| 7918 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7919 | if (hasReadPermission) { |
| 7920 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7921 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7922 | |
| 7923 | // Remove private info if the caller doesn't have access |
| 7924 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7925 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7926 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7927 | // is available |
| 7928 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7929 | if (card == null || card.getUiccProfile() == null) { |
| 7930 | // assume no access if the card or profile is unavailable |
| 7931 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7932 | continue; |
| 7933 | } |
| 7934 | UiccProfile profile = card.getUiccProfile(); |
| 7935 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7936 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7937 | filteredInfos.add(cardInfo); |
| 7938 | } else { |
| 7939 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7940 | } |
| 7941 | } |
| 7942 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7943 | } finally { |
| 7944 | Binder.restoreCallingIdentity(identity); |
| 7945 | } |
| 7946 | } |
| 7947 | |
| 7948 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7949 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7950 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | final long identity = Binder.clearCallingIdentity(); |
| 7953 | try { |
| 7954 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7955 | if (slots == null) { |
| 7956 | Rlog.i(LOG_TAG, "slots is null."); |
| 7957 | return null; |
| 7958 | } |
| 7959 | |
| 7960 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7961 | for (int i = 0; i < slots.length; i++) { |
| 7962 | UiccSlot slot = slots[i]; |
| 7963 | if (slot == null) { |
| 7964 | continue; |
| 7965 | } |
| 7966 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7967 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7968 | UiccCard card = slot.getUiccCard(); |
| 7969 | if (card != null) { |
| 7970 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7971 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7972 | cardId = slot.getEid(); |
| 7973 | if (TextUtils.isEmpty(cardId)) { |
| 7974 | cardId = slot.getIccId(); |
| 7975 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7976 | } |
| 7977 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7978 | if (cardId != null) { |
| 7979 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7980 | // if cardId is an EID, it's all digits so this is fine |
| 7981 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7982 | } |
| 7983 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7984 | int cardState = 0; |
| 7985 | switch (slot.getCardState()) { |
| 7986 | case CARDSTATE_ABSENT: |
| 7987 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7988 | break; |
| 7989 | case CARDSTATE_PRESENT: |
| 7990 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7991 | break; |
| 7992 | case CARDSTATE_ERROR: |
| 7993 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7994 | break; |
| 7995 | case CARDSTATE_RESTRICTED: |
| 7996 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7997 | break; |
| 7998 | default: |
| 7999 | break; |
| 8000 | |
| 8001 | } |
| 8002 | |
| 8003 | infos[i] = new UiccSlotInfo( |
| 8004 | slot.isActive(), |
| 8005 | slot.isEuicc(), |
| 8006 | cardId, |
| 8007 | cardState, |
| 8008 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8009 | slot.isExtendedApduSupported(), |
| 8010 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8011 | } |
| 8012 | return infos; |
| 8013 | } finally { |
| 8014 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8015 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8016 | } |
| 8017 | |
| 8018 | @Override |
| 8019 | public boolean switchSlots(int[] physicalSlots) { |
| 8020 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8021 | |
| 8022 | final long identity = Binder.clearCallingIdentity(); |
| 8023 | try { |
| 8024 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8025 | } finally { |
| 8026 | Binder.restoreCallingIdentity(identity); |
| 8027 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8028 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8029 | |
| 8030 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8031 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8032 | final long identity = Binder.clearCallingIdentity(); |
| 8033 | try { |
| 8034 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8035 | } finally { |
| 8036 | Binder.restoreCallingIdentity(identity); |
| 8037 | } |
| 8038 | } |
| 8039 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8040 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8041 | * A test API to reload the UICC profile. |
| 8042 | * |
| 8043 | * <p>Requires that the calling app has permission |
| 8044 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8045 | * @hide |
| 8046 | */ |
| 8047 | @Override |
| 8048 | public void refreshUiccProfile(int subId) { |
| 8049 | enforceModifyPermission(); |
| 8050 | |
| 8051 | final long identity = Binder.clearCallingIdentity(); |
| 8052 | try { |
| 8053 | Phone phone = getPhone(subId); |
| 8054 | if (phone == null) { |
| 8055 | return; |
| 8056 | } |
| 8057 | UiccCard uiccCard = phone.getUiccCard(); |
| 8058 | if (uiccCard == null) { |
| 8059 | return; |
| 8060 | } |
| 8061 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8062 | if (uiccProfile == null) { |
| 8063 | return; |
| 8064 | } |
| 8065 | uiccProfile.refresh(); |
| 8066 | } finally { |
| 8067 | Binder.restoreCallingIdentity(identity); |
| 8068 | } |
| 8069 | } |
| 8070 | |
| 8071 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8072 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8073 | */ |
| 8074 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8075 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8076 | } |
| 8077 | |
| 8078 | /** |
| 8079 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8080 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8081 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8082 | */ |
| 8083 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8084 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8085 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8086 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8087 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8088 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8089 | return isDataRoamingEnabled; |
| 8090 | } |
| 8091 | |
| 8092 | /** |
| 8093 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8094 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8095 | */ |
| 8096 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8097 | List<Integer> list = TelephonyProperties.default_network(); |
| 8098 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8099 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8100 | return list.get(phoneId); |
| 8101 | } |
| 8102 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8103 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8104 | |
| 8105 | @Override |
| 8106 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8107 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8108 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8109 | |
| 8110 | final long identity = Binder.clearCallingIdentity(); |
| 8111 | try { |
| 8112 | final Phone phone = getPhone(subId); |
| 8113 | if (phone == null) { |
| 8114 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8115 | return; |
| 8116 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8117 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8118 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8119 | if (carrierPrivilegeRules == null) { |
| 8120 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8121 | } else { |
| 8122 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8123 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8124 | } finally { |
| 8125 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8126 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8127 | } |
| 8128 | |
| 8129 | @Override |
| 8130 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8131 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8132 | |
| 8133 | final long identity = Binder.clearCallingIdentity(); |
| 8134 | try { |
| 8135 | final Phone phone = getPhone(subId); |
| 8136 | if (phone == null) { |
| 8137 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8138 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8139 | } |
| 8140 | return phone.getCarrierIdListVersion(); |
| 8141 | } finally { |
| 8142 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8143 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8144 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8145 | |
| 8146 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8147 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8148 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8149 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8150 | mApp, subId, callingPackage, callingFeatureId, |
| 8151 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8152 | return -1; |
| 8153 | } |
| 8154 | |
| 8155 | final long identity = Binder.clearCallingIdentity(); |
| 8156 | try { |
| 8157 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8158 | } finally { |
| 8159 | Binder.restoreCallingIdentity(identity); |
| 8160 | } |
| 8161 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8162 | |
| 8163 | @Override |
| 8164 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8165 | TelephonyPermissions |
| 8166 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8167 | mApp, subId, "getCdmaRoamingMode"); |
| 8168 | |
| 8169 | final long identity = Binder.clearCallingIdentity(); |
| 8170 | try { |
| 8171 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8172 | } finally { |
| 8173 | Binder.restoreCallingIdentity(identity); |
| 8174 | } |
| 8175 | } |
| 8176 | |
| 8177 | @Override |
| 8178 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8179 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8180 | mApp, subId, "setCdmaRoamingMode"); |
| 8181 | |
| 8182 | final long identity = Binder.clearCallingIdentity(); |
| 8183 | try { |
| 8184 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8185 | } finally { |
| 8186 | Binder.restoreCallingIdentity(identity); |
| 8187 | } |
| 8188 | } |
| 8189 | |
| 8190 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8191 | public int getCdmaSubscriptionMode(int subId) { |
| 8192 | TelephonyPermissions |
| 8193 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8194 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8195 | |
| 8196 | final long identity = Binder.clearCallingIdentity(); |
| 8197 | try { |
| 8198 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8199 | } finally { |
| 8200 | Binder.restoreCallingIdentity(identity); |
| 8201 | } |
| 8202 | } |
| 8203 | |
| 8204 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8205 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8206 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8207 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8208 | |
| 8209 | final long identity = Binder.clearCallingIdentity(); |
| 8210 | try { |
| 8211 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8212 | } finally { |
| 8213 | Binder.restoreCallingIdentity(identity); |
| 8214 | } |
| 8215 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8216 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8217 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8218 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8219 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8220 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8221 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8222 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8223 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8224 | } |
| 8225 | final long identity = Binder.clearCallingIdentity(); |
| 8226 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8227 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8228 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8229 | if (phone.getEmergencyNumberTracker() != null |
| 8230 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8231 | emergencyNumberListInternal.put( |
| 8232 | phone.getSubId(), |
| 8233 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8234 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8235 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8236 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8237 | } finally { |
| 8238 | Binder.restoreCallingIdentity(identity); |
| 8239 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8240 | } |
| 8241 | |
| 8242 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8243 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8244 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8245 | if (!exactMatch) { |
| 8246 | TelephonyPermissions |
| 8247 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8248 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8249 | } |
| 8250 | final long identity = Binder.clearCallingIdentity(); |
| 8251 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8252 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8253 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8254 | && phone.getEmergencyNumberTracker() |
| 8255 | .isEmergencyNumber(number, exactMatch)) { |
| 8256 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8257 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8258 | } |
| 8259 | return false; |
| 8260 | } finally { |
| 8261 | Binder.restoreCallingIdentity(identity); |
| 8262 | } |
| 8263 | } |
| 8264 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8265 | /** |
| 8266 | * Update emergency number list for test mode. |
| 8267 | */ |
| 8268 | @Override |
| 8269 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8270 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8271 | "updateEmergencyNumberListTestMode"); |
| 8272 | |
| 8273 | final long identity = Binder.clearCallingIdentity(); |
| 8274 | try { |
| 8275 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8276 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8277 | if (tracker != null) { |
| 8278 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8279 | } |
| 8280 | } |
| 8281 | } finally { |
| 8282 | Binder.restoreCallingIdentity(identity); |
| 8283 | } |
| 8284 | } |
| 8285 | |
| 8286 | /** |
| 8287 | * Get the full emergency number list for test mode. |
| 8288 | */ |
| 8289 | @Override |
| 8290 | public List<String> getEmergencyNumberListTestMode() { |
| 8291 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8292 | "getEmergencyNumberListTestMode"); |
| 8293 | |
| 8294 | final long identity = Binder.clearCallingIdentity(); |
| 8295 | try { |
| 8296 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8297 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8298 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8299 | if (tracker != null) { |
| 8300 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8301 | emergencyNumbers.add(num.getNumber()); |
| 8302 | } |
| 8303 | } |
| 8304 | } |
| 8305 | return new ArrayList<>(emergencyNumbers); |
| 8306 | } finally { |
| 8307 | Binder.restoreCallingIdentity(identity); |
| 8308 | } |
| 8309 | } |
| 8310 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8311 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8312 | public int getEmergencyNumberDbVersion(int subId) { |
| 8313 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8314 | |
| 8315 | final long identity = Binder.clearCallingIdentity(); |
| 8316 | try { |
| 8317 | final Phone phone = getPhone(subId); |
| 8318 | if (phone == null) { |
| 8319 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8320 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8321 | } |
| 8322 | return phone.getEmergencyNumberDbVersion(); |
| 8323 | } finally { |
| 8324 | Binder.restoreCallingIdentity(identity); |
| 8325 | } |
| 8326 | } |
| 8327 | |
| 8328 | @Override |
| 8329 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8330 | enforceModifyPermission(); |
| 8331 | |
| 8332 | final long identity = Binder.clearCallingIdentity(); |
| 8333 | try { |
| 8334 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8335 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8336 | if (tracker != null) { |
| 8337 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8338 | } |
| 8339 | } |
| 8340 | } finally { |
| 8341 | Binder.restoreCallingIdentity(identity); |
| 8342 | } |
| 8343 | } |
| 8344 | |
| 8345 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8346 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8347 | enforceActiveEmergencySessionPermission(); |
| 8348 | |
| 8349 | final long identity = Binder.clearCallingIdentity(); |
| 8350 | try { |
| 8351 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8352 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8353 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8354 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8355 | } |
| 8356 | } |
| 8357 | } finally { |
| 8358 | Binder.restoreCallingIdentity(identity); |
| 8359 | } |
| 8360 | } |
| 8361 | |
| 8362 | @Override |
| 8363 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8364 | enforceActiveEmergencySessionPermission(); |
| 8365 | |
| 8366 | final long identity = Binder.clearCallingIdentity(); |
| 8367 | try { |
| 8368 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8369 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8370 | if (tracker != null) { |
| 8371 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8372 | } |
| 8373 | } |
| 8374 | } finally { |
| 8375 | Binder.restoreCallingIdentity(identity); |
| 8376 | } |
| 8377 | } |
| 8378 | |
| 8379 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8380 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8381 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8382 | Phone phone = getPhone(subId); |
| 8383 | if (phone == null) { |
| 8384 | return null; |
| 8385 | } |
| 8386 | final long identity = Binder.clearCallingIdentity(); |
| 8387 | try { |
| 8388 | UiccProfile profile = UiccController.getInstance() |
| 8389 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8390 | if (profile != null) { |
| 8391 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8392 | } |
| 8393 | } finally { |
| 8394 | Binder.restoreCallingIdentity(identity); |
| 8395 | } |
| 8396 | return null; |
| 8397 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8398 | |
| 8399 | /** |
| 8400 | * Enable or disable a modem stack. |
| 8401 | */ |
| 8402 | @Override |
| 8403 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8404 | enforceModifyPermission(); |
| 8405 | |
| 8406 | final long identity = Binder.clearCallingIdentity(); |
| 8407 | try { |
| 8408 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8409 | if (phone == null) { |
| 8410 | return false; |
| 8411 | } else { |
| 8412 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8413 | } |
| 8414 | } finally { |
| 8415 | Binder.restoreCallingIdentity(identity); |
| 8416 | } |
| 8417 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8418 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8419 | /** |
| 8420 | * Whether a modem stack is enabled or not. |
| 8421 | */ |
| 8422 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8423 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8424 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8425 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8426 | if (phone == null) return false; |
| 8427 | |
| 8428 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8429 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8430 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8431 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8432 | } |
| 8433 | |
| 8434 | final long identity = Binder.clearCallingIdentity(); |
| 8435 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8436 | try { |
| 8437 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8438 | } catch (NoSuchElementException ex) { |
| 8439 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8440 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8441 | } finally { |
| 8442 | Binder.restoreCallingIdentity(identity); |
| 8443 | } |
| 8444 | } |
| 8445 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8446 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8447 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8448 | enforceModifyPermission(); |
| 8449 | |
| 8450 | final long identity = Binder.clearCallingIdentity(); |
| 8451 | try { |
| 8452 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8453 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8454 | .commit(); |
| 8455 | } finally { |
| 8456 | Binder.restoreCallingIdentity(identity); |
| 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8461 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8462 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8463 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8464 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8465 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8466 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8467 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8468 | |
| 8469 | final long identity = Binder.clearCallingIdentity(); |
| 8470 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8471 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8472 | } finally { |
| 8473 | Binder.restoreCallingIdentity(identity); |
| 8474 | } |
| 8475 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8476 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8477 | @TelephonyManager.IsMultiSimSupportedResult |
| 8478 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8479 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8480 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8481 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8482 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8483 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8484 | } |
| 8485 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8486 | // supported by the modem, indicate that it is restricted. |
| 8487 | PhoneCapability staticCapability = |
| 8488 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8489 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8490 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8491 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8492 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8493 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8494 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8495 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8496 | } |
| 8497 | // Check if support of multiple SIMs is restricted by carrier |
| 8498 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8499 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8500 | } |
| 8501 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8502 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8503 | } |
| 8504 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8505 | /** |
| 8506 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8507 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8508 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8509 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8510 | * @param numOfSims number of active sims we want to switch to |
| 8511 | */ |
| 8512 | @Override |
| 8513 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8514 | if (numOfSims == 1) { |
| 8515 | enforceModifyPermission(); |
| 8516 | } else { |
| 8517 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8518 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8519 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8520 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8521 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8522 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8523 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8524 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8525 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8526 | return; |
| 8527 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8528 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8529 | } finally { |
| 8530 | Binder.restoreCallingIdentity(identity); |
| 8531 | } |
| 8532 | } |
| 8533 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8534 | @Override |
| 8535 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8536 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8537 | Phone phone = getPhone(subId); |
| 8538 | if (phone == null) { |
| 8539 | return false; |
| 8540 | } |
| 8541 | final long identity = Binder.clearCallingIdentity(); |
| 8542 | try { |
| 8543 | UiccCard uiccCard = phone.getUiccCard(); |
| 8544 | if (uiccCard == null) { |
| 8545 | return false; |
| 8546 | } |
| 8547 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8548 | if (uiccProfile == null) { |
| 8549 | return false; |
| 8550 | } |
| 8551 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8552 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8553 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8554 | } |
| 8555 | return false; |
| 8556 | } finally { |
| 8557 | Binder.restoreCallingIdentity(identity); |
| 8558 | } |
| 8559 | } |
| 8560 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8561 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8562 | * Get whether making changes to modem configurations will trigger reboot. |
| 8563 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8564 | */ |
| 8565 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8566 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8567 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8568 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8569 | mApp, subId, callingPackage, callingFeatureId, |
| 8570 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8571 | return false; |
| 8572 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8573 | final long identity = Binder.clearCallingIdentity(); |
| 8574 | try { |
| 8575 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8576 | } finally { |
| 8577 | Binder.restoreCallingIdentity(identity); |
| 8578 | } |
| 8579 | } |
| 8580 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8581 | private void updateModemStateMetrics() { |
| 8582 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8583 | // TODO: check the state for each modem if the api is ready. |
| 8584 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8585 | } |
| 8586 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8587 | @Override |
| 8588 | public int[] getSlotsMapping() { |
| 8589 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8590 | |
| 8591 | final long identity = Binder.clearCallingIdentity(); |
| 8592 | try { |
| 8593 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8594 | // All logical slots should have a mapping to a physical slot. |
| 8595 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8596 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8597 | for (int i = 0; i < slotInfos.length; i++) { |
| 8598 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8599 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8600 | } |
| 8601 | } |
| 8602 | return logicalSlotsMapping; |
| 8603 | } finally { |
| 8604 | Binder.restoreCallingIdentity(identity); |
| 8605 | } |
| 8606 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8607 | |
| 8608 | /** |
| 8609 | * Get the IRadio HAL Version |
| 8610 | */ |
| 8611 | @Override |
| 8612 | public int getRadioHalVersion() { |
| 8613 | Phone phone = getDefaultPhone(); |
| 8614 | if (phone == null) return -1; |
| 8615 | HalVersion hv = phone.getHalVersion(); |
| 8616 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8617 | return hv.major * 100 + hv.minor; |
| 8618 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8619 | |
| 8620 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8621 | * Get the current calling package name. |
| 8622 | * @return the current calling package name |
| 8623 | */ |
| 8624 | @Override |
| 8625 | public String getCurrentPackageName() { |
| 8626 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8627 | } |
| 8628 | |
| 8629 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8630 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8631 | * corresponding network requests on a subId. |
| 8632 | * |
| 8633 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8634 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8635 | * 2) APN is un-metered for this subscription, or |
| 8636 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8637 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8638 | * |
| 8639 | * @return whether data is allowed for a apn type. |
| 8640 | * |
| 8641 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8642 | */ |
| 8643 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8644 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8645 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8646 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8647 | |
| 8648 | // Now that all security checks passes, perform the operation as ourselves. |
| 8649 | final long identity = Binder.clearCallingIdentity(); |
| 8650 | try { |
| 8651 | Phone phone = getPhone(subId); |
| 8652 | if (phone == null) return false; |
| 8653 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8654 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8655 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8656 | } finally { |
| 8657 | Binder.restoreCallingIdentity(identity); |
| 8658 | } |
| 8659 | } |
| 8660 | |
| 8661 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8662 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8663 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8664 | |
| 8665 | // Now that all security checks passes, perform the operation as ourselves. |
| 8666 | final long identity = Binder.clearCallingIdentity(); |
| 8667 | try { |
| 8668 | Phone phone = getPhone(subId); |
| 8669 | if (phone == null) return true; // By default return true. |
| 8670 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8671 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8672 | } finally { |
| 8673 | Binder.restoreCallingIdentity(identity); |
| 8674 | } |
| 8675 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8676 | |
| 8677 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8678 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8679 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8680 | enforceModifyPermission(); |
| 8681 | long token = Binder.clearCallingIdentity(); |
| 8682 | try { |
| 8683 | Phone phone = getPhone(subscriptionId); |
| 8684 | if (phone == null) { |
| 8685 | try { |
| 8686 | if (resultCallback != null) { |
| 8687 | resultCallback.accept(false); |
| 8688 | } |
| 8689 | } catch (RemoteException e) { |
| 8690 | // ignore |
| 8691 | } |
| 8692 | return; |
| 8693 | } |
| 8694 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8695 | Pair.create(specifiers, (x) -> { |
| 8696 | try { |
| 8697 | if (resultCallback != null) { |
| 8698 | resultCallback.accept(x); |
| 8699 | } |
| 8700 | } catch (RemoteException e) { |
| 8701 | // ignore |
| 8702 | } |
| 8703 | }); |
| 8704 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8705 | } finally { |
| 8706 | Binder.restoreCallingIdentity(token); |
| 8707 | } |
| 8708 | } |
| 8709 | |
| 8710 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8711 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8712 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8713 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8714 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8715 | if (iccRecords == null) { |
| 8716 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8717 | return false; |
| 8718 | } |
| 8719 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8720 | } |
| 8721 | |
| 8722 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8723 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8724 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8725 | if (callingPackage == null) { |
| 8726 | callingPackage = getCurrentPackageName(); |
| 8727 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8728 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8729 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8730 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8731 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8732 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8733 | } |
| 8734 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8735 | Intent intent = new Intent(); |
| 8736 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8737 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8738 | // Bring up choose default SMS subscription dialog right now |
| 8739 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8740 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8741 | mApp.startActivity(intent); |
| 8742 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8743 | |
| 8744 | @Override |
| 8745 | public String getMmsUAProfUrl(int subId) { |
| 8746 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8747 | final long identity = Binder.clearCallingIdentity(); |
| 8748 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8749 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8750 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8751 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8752 | return carrierUAProfUrl; |
| 8753 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8754 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8755 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8756 | } finally { |
| 8757 | Binder.restoreCallingIdentity(identity); |
| 8758 | } |
| 8759 | } |
| 8760 | |
| 8761 | @Override |
| 8762 | public String getMmsUserAgent(int subId) { |
| 8763 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8764 | final long identity = Binder.clearCallingIdentity(); |
| 8765 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8766 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8767 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8768 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8769 | return carrierUserAgent; |
| 8770 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8771 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8772 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8773 | } finally { |
| 8774 | Binder.restoreCallingIdentity(identity); |
| 8775 | } |
| 8776 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8777 | |
| 8778 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8779 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8780 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8781 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8782 | final long identity = Binder.clearCallingIdentity(); |
| 8783 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8784 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8785 | if (phone == null) return false; |
| 8786 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8787 | switch (policy) { |
| 8788 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8789 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8790 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8791 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8792 | default: |
| 8793 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8794 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8795 | } finally { |
| 8796 | Binder.restoreCallingIdentity(identity); |
| 8797 | } |
| 8798 | } |
| 8799 | |
| 8800 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8801 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8802 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8803 | enforceModifyPermission(); |
| 8804 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8805 | final long identity = Binder.clearCallingIdentity(); |
| 8806 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8807 | Phone phone = getPhone(subscriptionId); |
| 8808 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8809 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8810 | switch (policy) { |
| 8811 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8812 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8813 | break; |
| 8814 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8815 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 8816 | break; |
| 8817 | default: |
| 8818 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8819 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8820 | } finally { |
| 8821 | Binder.restoreCallingIdentity(identity); |
| 8822 | } |
| 8823 | } |
| 8824 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8825 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8826 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8827 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8828 | * otherwise. |
| 8829 | */ |
| 8830 | @Override |
| 8831 | public void setCepEnabled(boolean isCepEnabled) { |
| 8832 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8833 | |
| 8834 | final long identity = Binder.clearCallingIdentity(); |
| 8835 | try { |
| 8836 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8837 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8838 | Phone defaultPhone = phone.getImsPhone(); |
| 8839 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8840 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8841 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8842 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8843 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8844 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8845 | + imsPhone.getMsisdn()); |
| 8846 | } |
| 8847 | } |
| 8848 | } finally { |
| 8849 | Binder.restoreCallingIdentity(identity); |
| 8850 | } |
| 8851 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8852 | |
| 8853 | /** |
| 8854 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8855 | * |
| 8856 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8857 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8858 | * before being read. |
| 8859 | */ |
| 8860 | @Override |
| 8861 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8862 | isCompressed) { |
| 8863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8864 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8865 | try { |
| 8866 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8867 | if (configBinder == null) { |
| 8868 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8869 | } else { |
| 8870 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8871 | } |
| 8872 | } catch (RemoteException e) { |
| 8873 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8874 | } |
| 8875 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8876 | |
| 8877 | @Override |
| 8878 | public boolean isIccLockEnabled(int subId) { |
| 8879 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8880 | |
| 8881 | // Now that all security checks passes, perform the operation as ourselves. |
| 8882 | final long identity = Binder.clearCallingIdentity(); |
| 8883 | try { |
| 8884 | Phone phone = getPhone(subId); |
| 8885 | if (phone != null && phone.getIccCard() != null) { |
| 8886 | return phone.getIccCard().getIccLockEnabled(); |
| 8887 | } else { |
| 8888 | return false; |
| 8889 | } |
| 8890 | } finally { |
| 8891 | Binder.restoreCallingIdentity(identity); |
| 8892 | } |
| 8893 | } |
| 8894 | |
| 8895 | /** |
| 8896 | * Set the ICC pin lock enabled or disabled. |
| 8897 | * |
| 8898 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8899 | * three cases: |
| 8900 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8901 | * successfully. |
| 8902 | * - Positive number and zero for remaining password attempts. |
| 8903 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8904 | * |
| 8905 | */ |
| 8906 | @Override |
| 8907 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8908 | enforceModifyPermission(); |
| 8909 | |
| 8910 | Phone phone = getPhone(subId); |
| 8911 | if (phone == null) { |
| 8912 | return 0; |
| 8913 | } |
| 8914 | // Now that all security checks passes, perform the operation as ourselves. |
| 8915 | final long identity = Binder.clearCallingIdentity(); |
| 8916 | try { |
| 8917 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8918 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8919 | return attemptsRemaining; |
| 8920 | |
| 8921 | } catch (Exception e) { |
| 8922 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8923 | } finally { |
| 8924 | Binder.restoreCallingIdentity(identity); |
| 8925 | } |
| 8926 | return 0; |
| 8927 | } |
| 8928 | |
| 8929 | /** |
| 8930 | * Change the ICC password used in ICC pin lock. |
| 8931 | * |
| 8932 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8933 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8934 | * - Positive number and zero for remaining password attempts. |
| 8935 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8936 | * |
| 8937 | */ |
| 8938 | @Override |
| 8939 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8940 | enforceModifyPermission(); |
| 8941 | |
| 8942 | Phone phone = getPhone(subId); |
| 8943 | if (phone == null) { |
| 8944 | return 0; |
| 8945 | } |
| 8946 | // Now that all security checks passes, perform the operation as ourselves. |
| 8947 | final long identity = Binder.clearCallingIdentity(); |
| 8948 | try { |
| 8949 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8950 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8951 | return attemptsRemaining; |
| 8952 | |
| 8953 | } catch (Exception e) { |
| 8954 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8955 | } finally { |
| 8956 | Binder.restoreCallingIdentity(identity); |
| 8957 | } |
| 8958 | return 0; |
| 8959 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8960 | |
| 8961 | /** |
| 8962 | * Request for receiving user activity notification |
| 8963 | */ |
| 8964 | @Override |
| 8965 | public void requestUserActivityNotification() { |
| 8966 | if (!mNotifyUserActivity.get() |
| 8967 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8968 | mNotifyUserActivity.set(true); |
| 8969 | } |
| 8970 | } |
| 8971 | |
| 8972 | /** |
| 8973 | * Called when userActivity is signalled in the power manager. |
| 8974 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8975 | */ |
| 8976 | @Override |
| 8977 | public void userActivity() { |
| 8978 | // *************************************** |
| 8979 | // * Inherited from PhoneWindowManager * |
| 8980 | // *************************************** |
| 8981 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8982 | // WITH ITS LOCKS HELD. |
| 8983 | // |
| 8984 | // This code must be VERY careful about the locks |
| 8985 | // it acquires. |
| 8986 | // In fact, the current code acquires way too many, |
| 8987 | // and probably has lurking deadlocks. |
| 8988 | |
| 8989 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8990 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8991 | } |
| 8992 | |
| 8993 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8994 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8995 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8996 | } |
| 8997 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8998 | |
| 8999 | @Override |
| 9000 | public boolean canConnectTo5GInDsdsMode() { |
| 9001 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9002 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9003 | |
| 9004 | @Override |
| 9005 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9006 | String callingFeatureId) { |
| 9007 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9008 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9009 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9010 | } |
| 9011 | |
| 9012 | Phone phone = getPhone(subId); |
| 9013 | if (phone == null) { |
| 9014 | throw new RuntimeException("phone is not available"); |
| 9015 | } |
| 9016 | // Now that all security checks passes, perform the operation as ourselves. |
| 9017 | final long identity = Binder.clearCallingIdentity(); |
| 9018 | try { |
| 9019 | return phone.getEquivalentHomePlmns(); |
| 9020 | } finally { |
| 9021 | Binder.restoreCallingIdentity(identity); |
| 9022 | } |
| 9023 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9024 | } |