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; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 69 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 70 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 71 | import android.telephony.CellIdentityCdma; |
| 72 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfoGsm; |
| 75 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 76 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 77 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 78 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 79 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 80 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 81 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 82 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 83 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 85 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 88 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
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; |
Jordan Liu | 102b277 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 123 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IBooleanConsumer; |
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; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 175 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 176 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 178 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 180 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 181 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 182 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 183 | import java.io.FileDescriptor; |
| 184 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 186 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 187 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 190 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 191 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 192 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 193 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 194 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 195 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * Implementation of the ITelephony interface. |
| 199 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 200 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 202 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 203 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 204 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | |
| 206 | // Message codes used with mMainThreadHandler |
| 207 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 208 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 209 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 210 | private static final int CMD_OPEN_CHANNEL = 9; |
| 211 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 212 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 213 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 214 | private static final int CMD_NV_READ_ITEM = 13; |
| 215 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 216 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 217 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 218 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 219 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 220 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 221 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 222 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 223 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 224 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 225 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 226 | private static final int CMD_SEND_ENVELOPE = 25; |
| 227 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 228 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 229 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 230 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 231 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 232 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 233 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 234 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 235 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 236 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 237 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 238 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 239 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 240 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 241 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 242 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 243 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 244 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 245 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 246 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 247 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 248 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 249 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 250 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 251 | private static final int CMD_SWITCH_SLOTS = 50; |
| 252 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 253 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 254 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 255 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 256 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 257 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 258 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 259 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 260 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 261 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 262 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 263 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 264 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 265 | private static final int CMD_MODEM_REBOOT = 64; |
| 266 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 267 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 268 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 269 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 270 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 271 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 272 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 273 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 274 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 275 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 276 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 277 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 278 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 279 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 280 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 281 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 282 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 283 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 284 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 285 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 286 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 287 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 288 | private static final int CMD_GET_CALL_WAITING = 87; |
| 289 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 290 | private static final int CMD_SET_CALL_WAITING = 89; |
| 291 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 292 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 293 | // Parameters of select command. |
| 294 | private static final int SELECT_COMMAND = 0xA4; |
| 295 | private static final int SELECT_P1 = 0x04; |
| 296 | private static final int SELECT_P2 = 0; |
| 297 | private static final int SELECT_P3 = 0x10; |
| 298 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 299 | /** The singleton instance. */ |
| 300 | private static PhoneInterfaceManager sInstance; |
| 301 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 302 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 303 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 304 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 305 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 306 | private AppOpsManager mAppOps; |
| 307 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 308 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 309 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 310 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 311 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 312 | /** User Activity */ |
| 313 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 314 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 315 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 316 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 317 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 318 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 319 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 320 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 321 | // String to store multi SIM allowed |
| 322 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 323 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 324 | // The AID of ISD-R. |
| 325 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 326 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 327 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 328 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 329 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 330 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 331 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 332 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 333 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 334 | */ |
| 335 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 336 | "reset_network_erase_modem_config_enabled"; |
| 337 | |
| 338 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 339 | * A request object to use for transmitting data to an ICC. |
| 340 | */ |
| 341 | private static final class IccAPDUArgument { |
| 342 | public int channel, cla, command, p1, p2, p3; |
| 343 | public String data; |
| 344 | |
| 345 | public IccAPDUArgument(int channel, int cla, int command, |
| 346 | int p1, int p2, int p3, String data) { |
| 347 | this.channel = channel; |
| 348 | this.cla = cla; |
| 349 | this.command = command; |
| 350 | this.p1 = p1; |
| 351 | this.p2 = p2; |
| 352 | this.p3 = p3; |
| 353 | this.data = data; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 358 | * A request object to use for transmitting data to an ICC. |
| 359 | */ |
| 360 | private static final class ManualNetworkSelectionArgument { |
| 361 | public OperatorInfo operatorInfo; |
| 362 | public boolean persistSelection; |
| 363 | |
| 364 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 365 | this.operatorInfo = operatorInfo; |
| 366 | this.persistSelection = persistSelection; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 372 | * request after sending. The main thread will notify the request when it is complete. |
| 373 | */ |
| 374 | private static final class MainThreadRequest { |
| 375 | /** The argument to use for the request */ |
| 376 | public Object argument; |
| 377 | /** The result of the request that is run on the main thread */ |
| 378 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 379 | // The subscriber id that this request applies to. Defaults to |
| 380 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 381 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 383 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 384 | public Phone phone; |
| 385 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 386 | public WorkSource workSource; |
| 387 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 388 | public MainThreadRequest(Object argument) { |
| 389 | this.argument = argument; |
| 390 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 391 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 392 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 393 | this.argument = argument; |
| 394 | if (phone != null) { |
| 395 | this.phone = phone; |
| 396 | } |
| 397 | this.workSource = workSource; |
| 398 | } |
| 399 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 400 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 401 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 402 | if (subId != null) { |
| 403 | this.subId = subId; |
| 404 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 405 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 409 | private static final class IncomingThirdPartyCallArgs { |
| 410 | public final ComponentName component; |
| 411 | public final String callId; |
| 412 | public final String callerDisplayName; |
| 413 | |
| 414 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 415 | String callerDisplayName) { |
| 416 | this.component = component; |
| 417 | this.callId = callId; |
| 418 | this.callerDisplayName = callerDisplayName; |
| 419 | } |
| 420 | } |
| 421 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 422 | /** |
| 423 | * A handler that processes messages on the main thread in the phone process. Since many |
| 424 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 425 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 426 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 427 | * on, which will be notified when the operation completes and will contain the result of the |
| 428 | * request. |
| 429 | * |
| 430 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 431 | * note that request.result must be set to something non-null for the calling thread to |
| 432 | * unblock. |
| 433 | */ |
| 434 | private final class MainThreadHandler extends Handler { |
| 435 | @Override |
| 436 | public void handleMessage(Message msg) { |
| 437 | MainThreadRequest request; |
| 438 | Message onCompleted; |
| 439 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 440 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 441 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 442 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 443 | |
| 444 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 445 | case CMD_HANDLE_USSD_REQUEST: { |
| 446 | request = (MainThreadRequest) msg.obj; |
| 447 | final Phone phone = getPhoneFromRequest(request); |
| 448 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 449 | String ussdRequest = ussdObject.first; |
| 450 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 451 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 452 | if (!isUssdApiAllowed(request.subId)) { |
| 453 | // Carrier does not support use of this API, return failure. |
| 454 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 455 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 456 | Bundle returnData = new Bundle(); |
| 457 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 458 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 459 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 460 | request.result = true; |
| 461 | notifyRequester(request); |
| 462 | return; |
| 463 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 464 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 465 | try { |
| 466 | request.result = phone != null |
| 467 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 468 | } catch (CallStateException cse) { |
| 469 | request.result = false; |
| 470 | } |
| 471 | // Wake up the requesting thread |
| 472 | notifyRequester(request); |
| 473 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 476 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 478 | final Phone phone = getPhoneFromRequest(request); |
| 479 | request.result = phone != null ? |
| 480 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 481 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 482 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 483 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 484 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 488 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 490 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 491 | if (uiccCard == null) { |
| 492 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 493 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 494 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 495 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 497 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 498 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 499 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 500 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 501 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 502 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | break; |
| 504 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 505 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 506 | ar = (AsyncResult) msg.obj; |
| 507 | request = (MainThreadRequest) ar.userObj; |
| 508 | if (ar.exception == null && ar.result != null) { |
| 509 | request.result = ar.result; |
| 510 | } else { |
| 511 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 512 | if (ar.result == null) { |
| 513 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 514 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 515 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 516 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 517 | } else { |
| 518 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 519 | } |
| 520 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 522 | break; |
| 523 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 524 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 525 | request = (MainThreadRequest) msg.obj; |
| 526 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 527 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | if (uiccCard == null) { |
| 529 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 530 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | } else { |
| 533 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 534 | request); |
| 535 | uiccCard.iccTransmitApduBasicChannel( |
| 536 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 537 | iccArgument.p3, iccArgument.data, onCompleted); |
| 538 | } |
| 539 | break; |
| 540 | |
| 541 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 542 | ar = (AsyncResult) msg.obj; |
| 543 | request = (MainThreadRequest) ar.userObj; |
| 544 | if (ar.exception == null && ar.result != null) { |
| 545 | request.result = ar.result; |
| 546 | } else { |
| 547 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 548 | if (ar.result == null) { |
| 549 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 550 | } else if (ar.exception instanceof CommandException) { |
| 551 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 552 | ar.exception); |
| 553 | } else { |
| 554 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 555 | } |
| 556 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 557 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 558 | break; |
| 559 | |
| 560 | case CMD_EXCHANGE_SIM_IO: |
| 561 | request = (MainThreadRequest) msg.obj; |
| 562 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 563 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 564 | if (uiccCard == null) { |
| 565 | loge("iccExchangeSimIO: No UICC"); |
| 566 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 567 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 568 | } else { |
| 569 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 570 | request); |
| 571 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 572 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 573 | iccArgument.data, onCompleted); |
| 574 | } |
| 575 | break; |
| 576 | |
| 577 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 578 | ar = (AsyncResult) msg.obj; |
| 579 | request = (MainThreadRequest) ar.userObj; |
| 580 | if (ar.exception == null && ar.result != null) { |
| 581 | request.result = ar.result; |
| 582 | } else { |
| 583 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 584 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | break; |
| 587 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 588 | case CMD_SEND_ENVELOPE: |
| 589 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 590 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 591 | if (uiccCard == null) { |
| 592 | loge("sendEnvelopeWithStatus: No UICC"); |
| 593 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 594 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 595 | } else { |
| 596 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 597 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 598 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 599 | break; |
| 600 | |
| 601 | case EVENT_SEND_ENVELOPE_DONE: |
| 602 | ar = (AsyncResult) msg.obj; |
| 603 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 604 | if (ar.exception == null && ar.result != null) { |
| 605 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 606 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 607 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 608 | if (ar.result == null) { |
| 609 | loge("sendEnvelopeWithStatus: Empty response"); |
| 610 | } else if (ar.exception instanceof CommandException) { |
| 611 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 612 | ar.exception); |
| 613 | } else { |
| 614 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 615 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 616 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 618 | break; |
| 619 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | case CMD_OPEN_CHANNEL: |
| 621 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 622 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 623 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | if (uiccCard == null) { |
| 625 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 626 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 627 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 629 | } else { |
| 630 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 631 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 632 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 633 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | break; |
| 635 | |
| 636 | case EVENT_OPEN_CHANNEL_DONE: |
| 637 | ar = (AsyncResult) msg.obj; |
| 638 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 641 | int[] result = (int[]) ar.result; |
| 642 | int channelId = result[0]; |
| 643 | byte[] selectResponse = null; |
| 644 | if (result.length > 1) { |
| 645 | selectResponse = new byte[result.length - 1]; |
| 646 | for (int i = 1; i < result.length; ++i) { |
| 647 | selectResponse[i - 1] = (byte) result[i]; |
| 648 | } |
| 649 | } |
| 650 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 651 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 653 | if (ar.result == null) { |
| 654 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | if (ar.exception != null) { |
| 657 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 658 | } |
| 659 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 660 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 661 | if (ar.exception instanceof CommandException) { |
| 662 | CommandException.Error error = |
| 663 | ((CommandException) (ar.exception)).getCommandError(); |
| 664 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 665 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 666 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 667 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 671 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 673 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 674 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | break; |
| 676 | |
| 677 | case CMD_CLOSE_CHANNEL: |
| 678 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 679 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 680 | if (uiccCard == null) { |
| 681 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 682 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 683 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 684 | } else { |
| 685 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 686 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 687 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 692 | break; |
| 693 | |
| 694 | case CMD_NV_READ_ITEM: |
| 695 | request = (MainThreadRequest) msg.obj; |
| 696 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 697 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 698 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 699 | break; |
| 700 | |
| 701 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | ar = (AsyncResult) msg.obj; |
| 703 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 704 | if (ar.exception == null && ar.result != null) { |
| 705 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 707 | request.result = ""; |
| 708 | if (ar.result == null) { |
| 709 | loge("nvReadItem: Empty response"); |
| 710 | } else if (ar.exception instanceof CommandException) { |
| 711 | loge("nvReadItem: CommandException: " + |
| 712 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 713 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 718 | break; |
| 719 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 720 | case CMD_NV_WRITE_ITEM: |
| 721 | request = (MainThreadRequest) msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 723 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 724 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 725 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case EVENT_NV_WRITE_ITEM_DONE: |
| 729 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 730 | break; |
| 731 | |
| 732 | case CMD_NV_WRITE_CDMA_PRL: |
| 733 | request = (MainThreadRequest) msg.obj; |
| 734 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 735 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 739 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 740 | break; |
| 741 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 742 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 744 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 745 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 748 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 749 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 750 | break; |
| 751 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 752 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 753 | request = (MainThreadRequest) msg.obj; |
| 754 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 755 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 759 | ar = (AsyncResult) msg.obj; |
| 760 | request = (MainThreadRequest) ar.userObj; |
| 761 | if (ar.exception == null && ar.result != null) { |
| 762 | request.result = ar.result; // Integer |
| 763 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 764 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 765 | if (ar.result == null) { |
| 766 | loge("getPreferredNetworkType: Empty response"); |
| 767 | } else if (ar.exception instanceof CommandException) { |
| 768 | loge("getPreferredNetworkType: CommandException: " + |
| 769 | ar.exception); |
| 770 | } else { |
| 771 | loge("getPreferredNetworkType: Unknown exception"); |
| 772 | } |
| 773 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 774 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 778 | request = (MainThreadRequest) msg.obj; |
| 779 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 780 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 781 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 785 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 786 | break; |
| 787 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 788 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 789 | request = (MainThreadRequest)msg.obj; |
| 790 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 791 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 792 | break; |
| 793 | |
| 794 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 795 | ar = (AsyncResult)msg.obj; |
| 796 | request = (MainThreadRequest)ar.userObj; |
| 797 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 798 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 799 | break; |
| 800 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 801 | case CMD_SET_VOICEMAIL_NUMBER: |
| 802 | request = (MainThreadRequest) msg.obj; |
| 803 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 804 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 805 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 806 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 807 | break; |
| 808 | |
| 809 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 810 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 811 | break; |
| 812 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 813 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 814 | request = (MainThreadRequest) msg.obj; |
| 815 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 816 | request); |
| 817 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 818 | break; |
| 819 | |
| 820 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 821 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 822 | break; |
| 823 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 824 | case CMD_PERFORM_NETWORK_SCAN: |
| 825 | request = (MainThreadRequest) msg.obj; |
| 826 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 827 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 828 | break; |
| 829 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 830 | case CMD_GET_CALL_FORWARDING: |
| 831 | request = (MainThreadRequest) msg.obj; |
| 832 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 833 | int callForwardingReason = (Integer) request.argument; |
| 834 | getPhoneFromRequest(request).getCallForwardingOption( |
| 835 | callForwardingReason, onCompleted); |
| 836 | break; |
| 837 | |
| 838 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 839 | ar = (AsyncResult) msg.obj; |
| 840 | request = (MainThreadRequest) ar.userObj; |
| 841 | CallForwardingInfo callForwardingInfo = null; |
| 842 | if (ar.exception == null && ar.result != null) { |
| 843 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 844 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 845 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 846 | // any service for voice call. |
| 847 | if ((callForwardInfo.serviceClass |
| 848 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 849 | callForwardingInfo = new CallForwardingInfo( |
| 850 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 851 | callForwardInfo.number, |
| 852 | callForwardInfo.timeSeconds); |
| 853 | break; |
| 854 | } |
| 855 | } |
| 856 | // Didn't find a call forward info for voice call. |
| 857 | if (callForwardingInfo == null) { |
| 858 | callForwardingInfo = new CallForwardingInfo( |
| 859 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 860 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 861 | } |
| 862 | } else { |
| 863 | if (ar.result == null) { |
| 864 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 865 | } |
| 866 | if (ar.exception != null) { |
| 867 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 868 | } |
| 869 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 870 | if (ar.exception instanceof CommandException) { |
| 871 | CommandException.Error error = |
| 872 | ((CommandException) (ar.exception)).getCommandError(); |
| 873 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 874 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 875 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 876 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 877 | } |
| 878 | } |
| 879 | callForwardingInfo = new CallForwardingInfo( |
| 880 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 881 | } |
| 882 | request.result = callForwardingInfo; |
| 883 | notifyRequester(request); |
| 884 | break; |
| 885 | |
| 886 | case CMD_SET_CALL_FORWARDING: |
| 887 | request = (MainThreadRequest) msg.obj; |
| 888 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 889 | CallForwardingInfo callForwardingInfoToSet = |
| 890 | (CallForwardingInfo) request.argument; |
| 891 | getPhoneFromRequest(request).setCallForwardingOption( |
| 892 | callForwardingInfoToSet.getStatus(), |
| 893 | callForwardingInfoToSet.getReason(), |
| 894 | callForwardingInfoToSet.getNumber(), |
| 895 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 896 | break; |
| 897 | |
| 898 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 899 | ar = (AsyncResult) msg.obj; |
| 900 | request = (MainThreadRequest) ar.userObj; |
| 901 | if (ar.exception == null) { |
| 902 | request.result = true; |
| 903 | } else { |
| 904 | request.result = false; |
| 905 | loge("setCallForwarding exception: " + ar.exception); |
| 906 | } |
| 907 | notifyRequester(request); |
| 908 | break; |
| 909 | |
| 910 | case CMD_GET_CALL_WAITING: |
| 911 | request = (MainThreadRequest) msg.obj; |
| 912 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 913 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 914 | break; |
| 915 | |
| 916 | case EVENT_GET_CALL_WAITING_DONE: |
| 917 | ar = (AsyncResult) msg.obj; |
| 918 | request = (MainThreadRequest) ar.userObj; |
| 919 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 920 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 921 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 922 | // Service Class is a bit mask per 3gpp 27.007. |
| 923 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 924 | if (callForwardResults.length > 1 |
| 925 | && ((callForwardResults[1] |
| 926 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 927 | callForwardingStatus = callForwardResults[0] == 0 |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 928 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 929 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 930 | } else { |
| 931 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 932 | } |
| 933 | } else { |
| 934 | if (ar.result == null) { |
| 935 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 936 | } |
| 937 | if (ar.exception != null) { |
| 938 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 939 | } |
| 940 | if (ar.exception instanceof CommandException) { |
| 941 | CommandException.Error error = |
| 942 | ((CommandException) (ar.exception)).getCommandError(); |
| 943 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 944 | callForwardingStatus = |
| 945 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | request.result = callForwardingStatus; |
| 950 | notifyRequester(request); |
| 951 | break; |
| 952 | |
| 953 | case CMD_SET_CALL_WAITING: |
| 954 | request = (MainThreadRequest) msg.obj; |
| 955 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 956 | boolean isEnable = (Boolean) request.argument; |
| 957 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 958 | break; |
| 959 | |
| 960 | case EVENT_SET_CALL_WAITING_DONE: |
| 961 | ar = (AsyncResult) msg.obj; |
| 962 | request = (MainThreadRequest) ar.userObj; |
| 963 | if (ar.exception == null) { |
| 964 | request.result = true; |
| 965 | } else { |
| 966 | request.result = false; |
| 967 | loge("setCallWaiting exception: " + ar.exception); |
| 968 | } |
| 969 | notifyRequester(request); |
| 970 | break; |
| 971 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 972 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 973 | ar = (AsyncResult) msg.obj; |
| 974 | request = (MainThreadRequest) ar.userObj; |
| 975 | CellNetworkScanResult cellScanResult; |
| 976 | if (ar.exception == null && ar.result != null) { |
| 977 | cellScanResult = new CellNetworkScanResult( |
| 978 | CellNetworkScanResult.STATUS_SUCCESS, |
| 979 | (List<OperatorInfo>) ar.result); |
| 980 | } else { |
| 981 | if (ar.result == null) { |
| 982 | loge("getCellNetworkScanResults: Empty response"); |
| 983 | } |
| 984 | if (ar.exception != null) { |
| 985 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 986 | } |
| 987 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 988 | if (ar.exception instanceof CommandException) { |
| 989 | CommandException.Error error = |
| 990 | ((CommandException) (ar.exception)).getCommandError(); |
| 991 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 992 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 993 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 994 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 995 | } |
| 996 | } |
| 997 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 998 | } |
| 999 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1000 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1001 | break; |
| 1002 | |
| 1003 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1004 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1005 | ManualNetworkSelectionArgument selArg = |
| 1006 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1007 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1008 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1009 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1010 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1011 | break; |
| 1012 | |
| 1013 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1014 | ar = (AsyncResult) msg.obj; |
| 1015 | request = (MainThreadRequest) ar.userObj; |
| 1016 | if (ar.exception == null) { |
| 1017 | request.result = true; |
| 1018 | } else { |
| 1019 | request.result = false; |
| 1020 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1021 | } |
| 1022 | notifyRequester(request); |
| 1023 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1024 | break; |
| 1025 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1026 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1027 | request = (MainThreadRequest) msg.obj; |
| 1028 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1029 | if (defaultPhone != null) { |
| 1030 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 1031 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1032 | break; |
| 1033 | |
| 1034 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1035 | ar = (AsyncResult) msg.obj; |
| 1036 | request = (MainThreadRequest) ar.userObj; |
| 1037 | if (ar.exception == null && ar.result != null) { |
| 1038 | request.result = ar.result; |
| 1039 | } else { |
| 1040 | if (ar.result == null) { |
| 1041 | loge("queryModemActivityInfo: Empty response"); |
| 1042 | } else if (ar.exception instanceof CommandException) { |
| 1043 | loge("queryModemActivityInfo: CommandException: " + |
| 1044 | ar.exception); |
| 1045 | } else { |
| 1046 | loge("queryModemActivityInfo: Unknown exception"); |
| 1047 | } |
| 1048 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1049 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 1050 | if (request.result == null) { |
Peter Collingbourne | c00e902 | 2019-11-26 09:56:26 -0800 | [diff] [blame] | 1051 | request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 1052 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1053 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1054 | break; |
| 1055 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1056 | case CMD_SET_ALLOWED_CARRIERS: |
| 1057 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1058 | CarrierRestrictionRules argument = |
| 1059 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1060 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1061 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1062 | break; |
| 1063 | |
| 1064 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1065 | ar = (AsyncResult) msg.obj; |
| 1066 | request = (MainThreadRequest) ar.userObj; |
| 1067 | if (ar.exception == null && ar.result != null) { |
| 1068 | request.result = ar.result; |
| 1069 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1070 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1071 | if (ar.exception instanceof CommandException) { |
| 1072 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1073 | CommandException.Error error = |
| 1074 | ((CommandException) (ar.exception)).getCommandError(); |
| 1075 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1076 | request.result = |
| 1077 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1078 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1079 | } else { |
| 1080 | loge("setAllowedCarriers: Unknown exception"); |
| 1081 | } |
| 1082 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1083 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1084 | break; |
| 1085 | |
| 1086 | case CMD_GET_ALLOWED_CARRIERS: |
| 1087 | request = (MainThreadRequest) msg.obj; |
| 1088 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1089 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1090 | break; |
| 1091 | |
| 1092 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1093 | ar = (AsyncResult) msg.obj; |
| 1094 | request = (MainThreadRequest) ar.userObj; |
| 1095 | if (ar.exception == null && ar.result != null) { |
| 1096 | request.result = ar.result; |
| 1097 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1098 | request.result = new IllegalStateException( |
| 1099 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1100 | if (ar.result == null) { |
| 1101 | loge("getAllowedCarriers: Empty response"); |
| 1102 | } else if (ar.exception instanceof CommandException) { |
| 1103 | loge("getAllowedCarriers: CommandException: " + |
| 1104 | ar.exception); |
| 1105 | } else { |
| 1106 | loge("getAllowedCarriers: Unknown exception"); |
| 1107 | } |
| 1108 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1109 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1110 | break; |
| 1111 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1112 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1113 | ar = (AsyncResult) msg.obj; |
| 1114 | request = (MainThreadRequest) ar.userObj; |
| 1115 | if (ar.exception == null && ar.result != null) { |
| 1116 | request.result = ar.result; |
| 1117 | } else { |
| 1118 | request.result = new IllegalArgumentException( |
| 1119 | "Failed to retrieve Forbidden Plmns"); |
| 1120 | if (ar.result == null) { |
| 1121 | loge("getForbiddenPlmns: Empty response"); |
| 1122 | } else { |
| 1123 | loge("getForbiddenPlmns: Unknown exception"); |
| 1124 | } |
| 1125 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1126 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | |
| 1129 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1130 | request = (MainThreadRequest) msg.obj; |
| 1131 | uiccCard = getUiccCardFromRequest(request); |
| 1132 | if (uiccCard == null) { |
| 1133 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1134 | request.result = new IllegalArgumentException( |
| 1135 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1136 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1137 | break; |
| 1138 | } |
| 1139 | Integer appType = (Integer) request.argument; |
| 1140 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1141 | if (uiccApp == null) { |
| 1142 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1143 | + appType); |
| 1144 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1145 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1146 | break; |
| 1147 | } else { |
| 1148 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1149 | + " specified type -- " + appType); |
| 1150 | } |
| 1151 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1152 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1153 | onCompleted); |
| 1154 | break; |
| 1155 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1156 | case CMD_SWITCH_SLOTS: |
| 1157 | request = (MainThreadRequest) msg.obj; |
| 1158 | int[] physicalSlots = (int[]) request.argument; |
| 1159 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1160 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1161 | break; |
| 1162 | |
| 1163 | case EVENT_SWITCH_SLOTS_DONE: |
| 1164 | ar = (AsyncResult) msg.obj; |
| 1165 | request = (MainThreadRequest) ar.userObj; |
| 1166 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1167 | notifyRequester(request); |
| 1168 | break; |
| 1169 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1170 | request = (MainThreadRequest) msg.obj; |
| 1171 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1172 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1173 | break; |
| 1174 | |
| 1175 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1176 | ar = (AsyncResult) msg.obj; |
| 1177 | request = (MainThreadRequest) ar.userObj; |
| 1178 | if (ar.exception != null) { |
| 1179 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1180 | } else { |
| 1181 | int mode = ((int[]) ar.result)[0]; |
| 1182 | if (mode == 0) { |
| 1183 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1184 | } else { |
| 1185 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1186 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1187 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1188 | notifyRequester(request); |
| 1189 | break; |
| 1190 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1191 | request = (MainThreadRequest) msg.obj; |
| 1192 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1193 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1194 | break; |
| 1195 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1196 | ar = (AsyncResult) msg.obj; |
| 1197 | request = (MainThreadRequest) ar.userObj; |
| 1198 | if (ar.exception != null) { |
| 1199 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1200 | } else { |
| 1201 | request.result = ((int[]) ar.result)[0]; |
| 1202 | } |
| 1203 | notifyRequester(request); |
| 1204 | break; |
| 1205 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1206 | request = (MainThreadRequest) msg.obj; |
| 1207 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1208 | int mode = (int) request.argument; |
| 1209 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1210 | break; |
| 1211 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1212 | ar = (AsyncResult) msg.obj; |
| 1213 | request = (MainThreadRequest) ar.userObj; |
| 1214 | request.result = ar.exception == null; |
| 1215 | notifyRequester(request); |
| 1216 | break; |
| 1217 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1218 | request = (MainThreadRequest) msg.obj; |
| 1219 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1220 | int subscriptionMode = (int) request.argument; |
| 1221 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1222 | break; |
| 1223 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1224 | ar = (AsyncResult) msg.obj; |
| 1225 | request = (MainThreadRequest) ar.userObj; |
| 1226 | request.result = ar.exception == null; |
| 1227 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1228 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1229 | case CMD_GET_ALL_CELL_INFO: |
| 1230 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1231 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1232 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1233 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1234 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1235 | ar = (AsyncResult) msg.obj; |
| 1236 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1237 | // If a timeout occurs, the response will be null |
| 1238 | request.result = (ar.exception == null && ar.result != null) |
| 1239 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1240 | synchronized (request) { |
| 1241 | request.notifyAll(); |
| 1242 | } |
| 1243 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1244 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1245 | request = (MainThreadRequest) msg.obj; |
| 1246 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1247 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1248 | break; |
| 1249 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1250 | ar = (AsyncResult) msg.obj; |
| 1251 | request = (MainThreadRequest) ar.userObj; |
| 1252 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1253 | try { |
| 1254 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1255 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1256 | cb.onError( |
| 1257 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1258 | ar.exception.getClass().getName(), |
| 1259 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1260 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1261 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1262 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1263 | } else { |
| 1264 | // use the result as returned |
| 1265 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1266 | } |
| 1267 | } catch (RemoteException re) { |
| 1268 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1269 | } |
| 1270 | break; |
| 1271 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1272 | request = (MainThreadRequest) msg.obj; |
| 1273 | WorkSource ws = (WorkSource) request.argument; |
| 1274 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1275 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1276 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1277 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1278 | ar = (AsyncResult) msg.obj; |
| 1279 | request = (MainThreadRequest) ar.userObj; |
| 1280 | if (ar.exception == null) { |
| 1281 | request.result = ar.result; |
| 1282 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1283 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1284 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1285 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | synchronized (request) { |
| 1289 | request.notifyAll(); |
| 1290 | } |
| 1291 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1292 | case CMD_MODEM_REBOOT: |
| 1293 | request = (MainThreadRequest) msg.obj; |
| 1294 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1295 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1296 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1297 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1298 | handleNullReturnEvent(msg, "rebootModem"); |
| 1299 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1300 | case CMD_REQUEST_ENABLE_MODEM: |
| 1301 | request = (MainThreadRequest) msg.obj; |
| 1302 | boolean enable = (boolean) request.argument; |
| 1303 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1304 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1305 | PhoneConfigurationManager.getInstance() |
| 1306 | .enablePhone(request.phone, enable, onCompleted); |
| 1307 | break; |
| 1308 | case EVENT_ENABLE_MODEM_DONE: |
| 1309 | ar = (AsyncResult) msg.obj; |
| 1310 | request = (MainThreadRequest) ar.userObj; |
| 1311 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1312 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1313 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1314 | if ((boolean) request.result) { |
| 1315 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1316 | updateModemStateMetrics(); |
| 1317 | } else { |
| 1318 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1319 | + ar.exception); |
| 1320 | } |
| 1321 | notifyRequester(request); |
| 1322 | break; |
| 1323 | case CMD_GET_MODEM_STATUS: |
| 1324 | request = (MainThreadRequest) msg.obj; |
| 1325 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1326 | PhoneConfigurationManager.getInstance() |
| 1327 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1328 | break; |
| 1329 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1330 | ar = (AsyncResult) msg.obj; |
| 1331 | request = (MainThreadRequest) ar.userObj; |
| 1332 | int id = request.phone.getPhoneId(); |
| 1333 | if (ar.exception == null && ar.result != null) { |
| 1334 | request.result = ar.result; |
| 1335 | //update the cache as modem status has changed |
| 1336 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1337 | (boolean) request.result); |
| 1338 | } else { |
| 1339 | // Return true if modem status cannot be retrieved. For most cases, |
| 1340 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1341 | // and disable modem are not supported. Modem is always on. |
| 1342 | // TODO: this should be fixed in R to support a third |
| 1343 | // status UNKNOWN b/131631629 |
| 1344 | request.result = true; |
| 1345 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1346 | + ar.exception); |
| 1347 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1348 | notifyRequester(request); |
| 1349 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1350 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1351 | request = (MainThreadRequest) msg.obj; |
| 1352 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1353 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1354 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1355 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1356 | break; |
| 1357 | } |
| 1358 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1359 | ar = (AsyncResult) msg.obj; |
| 1360 | request = (MainThreadRequest) ar.userObj; |
| 1361 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1362 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1363 | args.second.accept(ar.exception == null); |
| 1364 | notifyRequester(request); |
| 1365 | break; |
| 1366 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1367 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1368 | ar = (AsyncResult) msg.obj; |
| 1369 | request = (MainThreadRequest) ar.userObj; |
| 1370 | if (ar.exception == null && ar.result != null) { |
| 1371 | request.result = ar.result; |
| 1372 | } else { |
| 1373 | request.result = -1; |
| 1374 | loge("Failed to set Forbidden Plmns"); |
| 1375 | if (ar.result == null) { |
| 1376 | loge("setForbidenPlmns: Empty response"); |
| 1377 | } else if (ar.exception != null) { |
| 1378 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1379 | request.result = -1; |
| 1380 | } else { |
| 1381 | loge("setForbiddenPlmns: Unknown exception"); |
| 1382 | } |
| 1383 | } |
| 1384 | notifyRequester(request); |
| 1385 | break; |
| 1386 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1387 | request = (MainThreadRequest) msg.obj; |
| 1388 | uiccCard = getUiccCardFromRequest(request); |
| 1389 | if (uiccCard == null) { |
| 1390 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1391 | request.result = -1; |
| 1392 | notifyRequester(request); |
| 1393 | break; |
| 1394 | } |
| 1395 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1396 | (Pair<Integer, List<String>>) request.argument; |
| 1397 | appType = setFplmnsArgs.first; |
| 1398 | List<String> fplmns = setFplmnsArgs.second; |
| 1399 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1400 | if (uiccApp == null) { |
| 1401 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1402 | request.result = -1; |
| 1403 | loge("Failed to get UICC App"); |
| 1404 | notifyRequester(request); |
| 1405 | } else { |
| 1406 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1407 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1408 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1409 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1410 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1411 | case CMD_ERASE_MODEM_CONFIG: |
| 1412 | request = (MainThreadRequest) msg.obj; |
| 1413 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1414 | defaultPhone.eraseModemConfig(onCompleted); |
| 1415 | break; |
| 1416 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1417 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1418 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1419 | |
| 1420 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1421 | request = (MainThreadRequest) msg.obj; |
| 1422 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1423 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1424 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1425 | changed.first, changed.second, onCompleted); |
| 1426 | break; |
| 1427 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1428 | ar = (AsyncResult) msg.obj; |
| 1429 | request = (MainThreadRequest) ar.userObj; |
| 1430 | if (ar.exception == null) { |
| 1431 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1432 | } else { |
| 1433 | request.result = msg.arg1; |
| 1434 | } |
| 1435 | notifyRequester(request); |
| 1436 | break; |
| 1437 | |
| 1438 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1439 | request = (MainThreadRequest) msg.obj; |
| 1440 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1441 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1442 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1443 | enabled.first, enabled.second, onCompleted); |
| 1444 | break; |
| 1445 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1446 | ar = (AsyncResult) msg.obj; |
| 1447 | request = (MainThreadRequest) ar.userObj; |
| 1448 | if (ar.exception == null) { |
| 1449 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1450 | } else { |
| 1451 | request.result = msg.arg1; |
| 1452 | } |
| 1453 | notifyRequester(request); |
| 1454 | break; |
| 1455 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1456 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1457 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1458 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1459 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1460 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1461 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1462 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1463 | default: |
| 1464 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1465 | break; |
| 1466 | } |
| 1467 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1468 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1469 | private void notifyRequester(MainThreadRequest request) { |
| 1470 | synchronized (request) { |
| 1471 | request.notifyAll(); |
| 1472 | } |
| 1473 | } |
| 1474 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1475 | private void handleNullReturnEvent(Message msg, String command) { |
| 1476 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1477 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1478 | if (ar.exception == null) { |
| 1479 | request.result = true; |
| 1480 | } else { |
| 1481 | request.result = false; |
| 1482 | if (ar.exception instanceof CommandException) { |
| 1483 | loge(command + ": CommandException: " + ar.exception); |
| 1484 | } else { |
| 1485 | loge(command + ": Unknown exception"); |
| 1486 | } |
| 1487 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1488 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1489 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | /** |
| 1493 | * Posts the specified command to be executed on the main thread, |
| 1494 | * waits for the request to complete, and returns the result. |
| 1495 | * @see #sendRequestAsync |
| 1496 | */ |
| 1497 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1498 | return sendRequest( |
| 1499 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /** |
| 1503 | * Posts the specified command to be executed on the main thread, |
| 1504 | * waits for the request to complete, and returns the result. |
| 1505 | * @see #sendRequestAsync |
| 1506 | */ |
| 1507 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1508 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1509 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | /** |
| 1513 | * Posts the specified command to be executed on the main thread, |
| 1514 | * waits for the request to complete, and returns the result. |
| 1515 | * @see #sendRequestAsync |
| 1516 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1517 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1518 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * Posts the specified command to be executed on the main thread, |
| 1523 | * waits for the request to complete, and returns the result. |
| 1524 | * @see #sendRequestAsync |
| 1525 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1526 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1527 | return sendRequest(command, argument, subId, null, workSource); |
| 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * Posts the specified command to be executed on the main thread, |
| 1532 | * waits for the request to complete, and returns the result. |
| 1533 | * @see #sendRequestAsync |
| 1534 | */ |
| 1535 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1536 | return sendRequest( |
| 1537 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * Posts the specified command to be executed on the main thread, |
| 1542 | * waits for the request to complete, and returns the result. |
| 1543 | * @see #sendRequestAsync |
| 1544 | */ |
| 1545 | private Object sendRequest( |
| 1546 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1547 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1548 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1549 | } |
| 1550 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1551 | MainThreadRequest request = null; |
| 1552 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1553 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1554 | } else if (phone != null) { |
| 1555 | request = new MainThreadRequest(argument, phone, workSource); |
| 1556 | } else { |
| 1557 | request = new MainThreadRequest(argument, subId, workSource); |
| 1558 | } |
| 1559 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1560 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1561 | msg.sendToTarget(); |
| 1562 | |
| 1563 | // Wait for the request to complete |
| 1564 | synchronized (request) { |
| 1565 | while (request.result == null) { |
| 1566 | try { |
| 1567 | request.wait(); |
| 1568 | } catch (InterruptedException e) { |
| 1569 | // Do nothing, go back and wait until the request is complete |
| 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | return request.result; |
| 1574 | } |
| 1575 | |
| 1576 | /** |
| 1577 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1578 | * Posts the specified command to be executed on the main thread, and |
| 1579 | * returns immediately. |
| 1580 | * @see #sendRequest |
| 1581 | */ |
| 1582 | private void sendRequestAsync(int command) { |
| 1583 | mMainThreadHandler.sendEmptyMessage(command); |
| 1584 | } |
| 1585 | |
| 1586 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1587 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1588 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1589 | */ |
| 1590 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1591 | sendRequestAsync(command, argument, null, null); |
| 1592 | } |
| 1593 | |
| 1594 | /** |
| 1595 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1596 | * @see {@link #sendRequest(int,Object)} |
| 1597 | */ |
| 1598 | private void sendRequestAsync( |
| 1599 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1600 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1601 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1602 | msg.sendToTarget(); |
| 1603 | } |
| 1604 | |
| 1605 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1606 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1607 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1608 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1609 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1610 | synchronized (PhoneInterfaceManager.class) { |
| 1611 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1612 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1613 | } else { |
| 1614 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1615 | } |
| 1616 | return sInstance; |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | /** Private constructor; @see init() */ |
Jordan Liu | 102b277 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 1621 | @VisibleForTesting |
| 1622 | /* package */ PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1623 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1624 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1625 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1626 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1627 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1628 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1629 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1630 | mTelephonySharedPreferences = |
| 1631 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1632 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1633 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1634 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1635 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1636 | publish(); |
| 1637 | } |
| 1638 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1639 | private Phone getDefaultPhone() { |
| 1640 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1641 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1642 | } |
| 1643 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1644 | private void publish() { |
| 1645 | if (DBG) log("publish: " + this); |
| 1646 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1647 | TelephonyFrameworkInitializer |
| 1648 | .getTelephonyServiceManager() |
| 1649 | .getTelephonyServiceRegisterer() |
| 1650 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1653 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1654 | if (request.phone != null) { |
| 1655 | return request.phone; |
| 1656 | } else { |
| 1657 | return getPhoneFromSubId(request.subId); |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | private Phone getPhoneFromSubId(int subId) { |
| 1662 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1663 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1666 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1667 | Phone phone = getPhoneFromRequest(request); |
| 1668 | return phone == null ? null : |
| 1669 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1670 | } |
| 1671 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1672 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1673 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1674 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1676 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1677 | private void sendEraseModemConfig(Phone phone) { |
| 1678 | if (phone != null) { |
| 1679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1680 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1681 | final long identity = Binder.clearCallingIdentity(); |
| 1682 | try { |
| 1683 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1684 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1685 | } finally { |
| 1686 | Binder.restoreCallingIdentity(identity); |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1691 | private boolean isImsAvailableOnDevice() { |
| 1692 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1693 | if (pm == null) { |
| 1694 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1695 | // so do not throw error and allow. |
| 1696 | return true; |
| 1697 | } |
| 1698 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1699 | } |
| 1700 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1701 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1702 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1705 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1706 | if (DBG) log("dial: " + number); |
| 1707 | // No permission check needed here: This is just a wrapper around the |
| 1708 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1709 | // the UI before it does anything. |
| 1710 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1711 | final long identity = Binder.clearCallingIdentity(); |
| 1712 | try { |
| 1713 | String url = createTelUrl(number); |
| 1714 | if (url == null) { |
| 1715 | return; |
| 1716 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1718 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1719 | PhoneConstants.State state = mCM.getState(subId); |
| 1720 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1721 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1722 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1723 | mApp.startActivity(intent); |
| 1724 | } |
| 1725 | } finally { |
| 1726 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1731 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1734 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1735 | if (DBG) log("call: " + number); |
| 1736 | |
| 1737 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1738 | // need to do a permission check since we're calling startActivity() |
| 1739 | // from the context of the phone app. |
| 1740 | enforceCallPermission(); |
| 1741 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1742 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1743 | != AppOpsManager.MODE_ALLOWED) { |
| 1744 | return; |
| 1745 | } |
| 1746 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1747 | final long identity = Binder.clearCallingIdentity(); |
| 1748 | try { |
| 1749 | String url = createTelUrl(number); |
| 1750 | if (url == null) { |
| 1751 | return; |
| 1752 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1753 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1754 | boolean isValid = false; |
| 1755 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1756 | if (slist != null) { |
| 1757 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1758 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1759 | isValid = true; |
| 1760 | break; |
| 1761 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1762 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1763 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1764 | if (!isValid) { |
| 1765 | return; |
| 1766 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1768 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1769 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1770 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1771 | mApp.startActivity(intent); |
| 1772 | } finally { |
| 1773 | Binder.restoreCallingIdentity(identity); |
| 1774 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1777 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1778 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1779 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1780 | } |
| 1781 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1782 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1783 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1784 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1785 | } |
| 1786 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1787 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1788 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1789 | |
| 1790 | final long identity = Binder.clearCallingIdentity(); |
| 1791 | try { |
| 1792 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1793 | checkSimPin.start(); |
| 1794 | return checkSimPin.unlockSim(null, pin); |
| 1795 | } finally { |
| 1796 | Binder.restoreCallingIdentity(identity); |
| 1797 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1800 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1801 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1802 | |
| 1803 | final long identity = Binder.clearCallingIdentity(); |
| 1804 | try { |
| 1805 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1806 | checkSimPuk.start(); |
| 1807 | return checkSimPuk.unlockSim(puk, pin); |
| 1808 | } finally { |
| 1809 | Binder.restoreCallingIdentity(identity); |
| 1810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1814 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1815 | * a synchronous one. |
| 1816 | */ |
| 1817 | private static class UnlockSim extends Thread { |
| 1818 | |
| 1819 | private final IccCard mSimCard; |
| 1820 | |
| 1821 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1822 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1823 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1824 | |
| 1825 | // For replies from SimCard interface |
| 1826 | private Handler mHandler; |
| 1827 | |
| 1828 | // For async handler to identify request type |
| 1829 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1830 | |
| 1831 | public UnlockSim(IccCard simCard) { |
| 1832 | mSimCard = simCard; |
| 1833 | } |
| 1834 | |
| 1835 | @Override |
| 1836 | public void run() { |
| 1837 | Looper.prepare(); |
| 1838 | synchronized (UnlockSim.this) { |
| 1839 | mHandler = new Handler() { |
| 1840 | @Override |
| 1841 | public void handleMessage(Message msg) { |
| 1842 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1843 | switch (msg.what) { |
| 1844 | case SUPPLY_PIN_COMPLETE: |
| 1845 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1846 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1847 | mRetryCount = msg.arg1; |
| 1848 | if (ar.exception != null) { |
| 1849 | if (ar.exception instanceof CommandException && |
| 1850 | ((CommandException)(ar.exception)).getCommandError() |
| 1851 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1852 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1853 | } else { |
| 1854 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1855 | } |
| 1856 | } else { |
| 1857 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1858 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1859 | mDone = true; |
| 1860 | UnlockSim.this.notifyAll(); |
| 1861 | } |
| 1862 | break; |
| 1863 | } |
| 1864 | } |
| 1865 | }; |
| 1866 | UnlockSim.this.notifyAll(); |
| 1867 | } |
| 1868 | Looper.loop(); |
| 1869 | } |
| 1870 | |
| 1871 | /* |
| 1872 | * Use PIN or PUK to unlock SIM card |
| 1873 | * |
| 1874 | * If PUK is null, unlock SIM card with PIN |
| 1875 | * |
| 1876 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1877 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1878 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | |
| 1880 | while (mHandler == null) { |
| 1881 | try { |
| 1882 | wait(); |
| 1883 | } catch (InterruptedException e) { |
| 1884 | Thread.currentThread().interrupt(); |
| 1885 | } |
| 1886 | } |
| 1887 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1888 | |
| 1889 | if (puk == null) { |
| 1890 | mSimCard.supplyPin(pin, callback); |
| 1891 | } else { |
| 1892 | mSimCard.supplyPuk(puk, pin, callback); |
| 1893 | } |
| 1894 | |
| 1895 | while (!mDone) { |
| 1896 | try { |
| 1897 | Log.d(LOG_TAG, "wait for done"); |
| 1898 | wait(); |
| 1899 | } catch (InterruptedException e) { |
| 1900 | // Restore the interrupted status |
| 1901 | Thread.currentThread().interrupt(); |
| 1902 | } |
| 1903 | } |
| 1904 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1905 | int[] resultArray = new int[2]; |
| 1906 | resultArray[0] = mResult; |
| 1907 | resultArray[1] = mRetryCount; |
| 1908 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1913 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1914 | |
| 1915 | } |
| 1916 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1917 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1918 | // No permission check needed here: this call is harmless, and it's |
| 1919 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1920 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1921 | final long identity = Binder.clearCallingIdentity(); |
| 1922 | try { |
| 1923 | final Phone phone = getPhone(subId); |
| 1924 | if (phone != null) { |
| 1925 | phone.updateServiceLocation(); |
| 1926 | } |
| 1927 | } finally { |
| 1928 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1929 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1932 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1933 | @Override |
| 1934 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1935 | return isRadioOnWithFeature(callingPackage, null); |
| 1936 | } |
| 1937 | |
| 1938 | |
| 1939 | @Override |
| 1940 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1941 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1942 | callingFeatureId); |
| 1943 | } |
| 1944 | |
| 1945 | @Deprecated |
| 1946 | @Override |
| 1947 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1948 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1951 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1952 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1953 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1954 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1955 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1956 | return false; |
| 1957 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1958 | |
| 1959 | final long identity = Binder.clearCallingIdentity(); |
| 1960 | try { |
| 1961 | return isRadioOnForSubscriber(subId); |
| 1962 | } finally { |
| 1963 | Binder.restoreCallingIdentity(identity); |
| 1964 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1968 | final long identity = Binder.clearCallingIdentity(); |
| 1969 | try { |
| 1970 | final Phone phone = getPhone(subId); |
| 1971 | if (phone != null) { |
| 1972 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1973 | } else { |
| 1974 | return false; |
| 1975 | } |
| 1976 | } finally { |
| 1977 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1978 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1982 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1983 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1984 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1985 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1986 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1987 | |
| 1988 | final long identity = Binder.clearCallingIdentity(); |
| 1989 | try { |
| 1990 | final Phone phone = getPhone(subId); |
| 1991 | if (phone != null) { |
| 1992 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1993 | } |
| 1994 | } finally { |
| 1995 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1996 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2000 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2003 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2004 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2005 | |
| 2006 | final long identity = Binder.clearCallingIdentity(); |
| 2007 | try { |
| 2008 | final Phone phone = getPhone(subId); |
| 2009 | if (phone == null) { |
| 2010 | return false; |
| 2011 | } |
| 2012 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2013 | toggleRadioOnOffForSubscriber(subId); |
| 2014 | } |
| 2015 | return true; |
| 2016 | } finally { |
| 2017 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2018 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2019 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2020 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2021 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2022 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2023 | /* |
| 2024 | * If any of the Radios are available, it will need to be |
| 2025 | * shutdown. So return true if any Radio is available. |
| 2026 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2027 | final long identity = Binder.clearCallingIdentity(); |
| 2028 | try { |
| 2029 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2030 | Phone phone = PhoneFactory.getPhone(i); |
| 2031 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2032 | } |
| 2033 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2034 | return false; |
| 2035 | } finally { |
| 2036 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2037 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2040 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2041 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | enforceModifyPermission(); |
| 2043 | |
| 2044 | final long identity = Binder.clearCallingIdentity(); |
| 2045 | try { |
| 2046 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2047 | logv("Shutting down Phone " + i); |
| 2048 | shutdownRadioUsingPhoneId(i); |
| 2049 | } |
| 2050 | } finally { |
| 2051 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2056 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2057 | if (phone != null && phone.isRadioAvailable()) { |
| 2058 | phone.shutdownRadio(); |
| 2059 | } |
| 2060 | } |
| 2061 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2062 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2063 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2064 | |
| 2065 | final long identity = Binder.clearCallingIdentity(); |
| 2066 | try { |
| 2067 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2068 | if (defaultPhone != null) { |
| 2069 | defaultPhone.setRadioPower(turnOn); |
| 2070 | return true; |
| 2071 | } else { |
| 2072 | loge("There's no default phone."); |
| 2073 | return false; |
| 2074 | } |
| 2075 | } finally { |
| 2076 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2077 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2080 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2081 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2082 | |
| 2083 | final long identity = Binder.clearCallingIdentity(); |
| 2084 | try { |
| 2085 | final Phone phone = getPhone(subId); |
| 2086 | if (phone != null) { |
| 2087 | phone.setRadioPower(turnOn); |
| 2088 | return true; |
| 2089 | } else { |
| 2090 | return false; |
| 2091 | } |
| 2092 | } finally { |
| 2093 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2094 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2097 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2098 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | public boolean enableDataConnectivity() { |
| 2100 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2101 | |
| 2102 | final long identity = Binder.clearCallingIdentity(); |
| 2103 | try { |
| 2104 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2105 | final Phone phone = getPhone(subId); |
| 2106 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2107 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2108 | return true; |
| 2109 | } else { |
| 2110 | return false; |
| 2111 | } |
| 2112 | } finally { |
| 2113 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2117 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2118 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2119 | public boolean disableDataConnectivity() { |
| 2120 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2121 | |
| 2122 | final long identity = Binder.clearCallingIdentity(); |
| 2123 | try { |
| 2124 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2125 | final Phone phone = getPhone(subId); |
| 2126 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2127 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2128 | return true; |
| 2129 | } else { |
| 2130 | return false; |
| 2131 | } |
| 2132 | } finally { |
| 2133 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2134 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2137 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2138 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2139 | final long identity = Binder.clearCallingIdentity(); |
| 2140 | try { |
| 2141 | final Phone phone = getPhone(subId); |
| 2142 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2143 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2144 | } else { |
| 2145 | return false; |
| 2146 | } |
| 2147 | } finally { |
| 2148 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2149 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2153 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2156 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2157 | enforceCallPermission(); |
| 2158 | |
| 2159 | final long identity = Binder.clearCallingIdentity(); |
| 2160 | try { |
| 2161 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2162 | return; |
| 2163 | } |
| 2164 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2165 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2166 | } finally { |
| 2167 | Binder.restoreCallingIdentity(identity); |
| 2168 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2169 | }; |
| 2170 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2171 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2173 | |
| 2174 | final long identity = Binder.clearCallingIdentity(); |
| 2175 | try { |
| 2176 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2177 | return false; |
| 2178 | } |
| 2179 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2180 | } finally { |
| 2181 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2182 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2185 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2186 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2189 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2190 | final long identity = Binder.clearCallingIdentity(); |
| 2191 | try { |
| 2192 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2193 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2194 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2195 | } finally { |
| 2196 | Binder.restoreCallingIdentity(identity); |
| 2197 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2200 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2201 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2202 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2203 | } |
| 2204 | |
| 2205 | @Override |
| 2206 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2207 | final long identity = Binder.clearCallingIdentity(); |
| 2208 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2209 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2210 | if (phone != null) { |
| 2211 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2212 | } else { |
| 2213 | return PhoneConstantConversions.convertDataState( |
| 2214 | PhoneConstants.DataState.DISCONNECTED); |
| 2215 | } |
| 2216 | } finally { |
| 2217 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2218 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2221 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2222 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2223 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2224 | } |
| 2225 | |
| 2226 | @Override |
| 2227 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2228 | final long identity = Binder.clearCallingIdentity(); |
| 2229 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2230 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2231 | if (phone != null) { |
| 2232 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2233 | } else { |
| 2234 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2235 | } |
| 2236 | } finally { |
| 2237 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2238 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
| 2241 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2242 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2243 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2244 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2245 | |
| 2246 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2247 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2248 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2249 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2250 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2251 | .setCallingPid(Binder.getCallingPid()) |
| 2252 | .setCallingUid(Binder.getCallingUid()) |
| 2253 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2254 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2255 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2256 | .build()); |
| 2257 | switch (locationResult) { |
| 2258 | case DENIED_HARD: |
| 2259 | throw new SecurityException("Not allowed to access cell location"); |
| 2260 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2261 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2262 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2265 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2266 | final long identity = Binder.clearCallingIdentity(); |
| 2267 | try { |
| 2268 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2269 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2270 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2271 | } finally { |
| 2272 | Binder.restoreCallingIdentity(identity); |
| 2273 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2276 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2277 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2278 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2279 | // registered cell info, so return a NULL country instead. |
| 2280 | final long identity = Binder.clearCallingIdentity(); |
| 2281 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2282 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2283 | // Get default phone in this case. |
| 2284 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2285 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2286 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2287 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2288 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2289 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2290 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2291 | mApp.getFeatureId())) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2292 | return ""; |
| 2293 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2294 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2295 | if (phone != null) { |
| 2296 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2297 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2298 | if (sst != null) { |
| 2299 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2300 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2301 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2302 | return lt.getCurrentCountry(); |
| 2303 | } else if (emergencyNumberTracker != null) { |
| 2304 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2305 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | } |
| 2309 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2310 | } finally { |
| 2311 | Binder.restoreCallingIdentity(identity); |
| 2312 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2316 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2317 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2320 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2321 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2322 | mApp.enforceCallingOrSelfPermission( |
| 2323 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2324 | |
| 2325 | final long identity = Binder.clearCallingIdentity(); |
| 2326 | try { |
| 2327 | final Phone phone = getPhone(subId); |
| 2328 | if (phone != null) { |
| 2329 | phone.enableLocationUpdates(); |
| 2330 | } |
| 2331 | } finally { |
| 2332 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2333 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | @Override |
| 2337 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2338 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2341 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2342 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2343 | mApp.enforceCallingOrSelfPermission( |
| 2344 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2345 | |
| 2346 | final long identity = Binder.clearCallingIdentity(); |
| 2347 | try { |
| 2348 | final Phone phone = getPhone(subId); |
| 2349 | if (phone != null) { |
| 2350 | phone.disableLocationUpdates(); |
| 2351 | } |
| 2352 | } finally { |
| 2353 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2354 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2357 | /** |
| 2358 | * Returns the target SDK version number for a given package name. |
| 2359 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2360 | * This call MUST be invoked before clearing the calling UID. |
| 2361 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2362 | * @return target SDK if the package is found or INT_MAX. |
| 2363 | */ |
| 2364 | private int getTargetSdk(String packageName) { |
| 2365 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2366 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2367 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2368 | if (ai != null) return ai.targetSdkVersion; |
| 2369 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2370 | loge("Failed to get package info for pkg=" |
| 2371 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2372 | } |
| 2373 | return Integer.MAX_VALUE; |
| 2374 | } |
| 2375 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2376 | @Override |
| 2377 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2378 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2379 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2380 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2381 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2382 | throw new SecurityException( |
| 2383 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2384 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2385 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2386 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2388 | return null; |
| 2389 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2390 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2391 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2393 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2394 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2396 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2397 | for (CellInfo ci : info) { |
| 2398 | if (ci instanceof CellInfoGsm) { |
| 2399 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2400 | } else if (ci instanceof CellInfoWcdma) { |
| 2401 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2402 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2404 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2407 | private List<CellInfo> getCachedCellInfo() { |
| 2408 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2409 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2410 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2411 | if (info != null) cellInfos.addAll(info); |
| 2412 | } |
| 2413 | return cellInfos; |
| 2414 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | |
| 2416 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2417 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2418 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2419 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2420 | |
| 2421 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2422 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2423 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2424 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2425 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2426 | .setCallingPid(Binder.getCallingPid()) |
| 2427 | .setCallingUid(Binder.getCallingUid()) |
| 2428 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2429 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2430 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2431 | .build()); |
| 2432 | switch (locationResult) { |
| 2433 | case DENIED_HARD: |
| 2434 | throw new SecurityException("Not allowed to access cell info"); |
| 2435 | case DENIED_SOFT: |
| 2436 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2439 | final int targetSdk = getTargetSdk(callingPackage); |
| 2440 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2441 | return getCachedCellInfo(); |
| 2442 | } |
| 2443 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2444 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2445 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | final long identity = Binder.clearCallingIdentity(); |
| 2447 | try { |
| 2448 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2449 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2450 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2451 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2452 | if (info != null) cellInfos.addAll(info); |
| 2453 | } |
| 2454 | return cellInfos; |
| 2455 | } finally { |
| 2456 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | } |
| 2458 | } |
| 2459 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2460 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2461 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2462 | String callingFeatureId) { |
| 2463 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2464 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2468 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2469 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2470 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2471 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2474 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2475 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2476 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2477 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2478 | |
| 2479 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2480 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2481 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2482 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2483 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2484 | .setCallingPid(Binder.getCallingPid()) |
| 2485 | .setCallingUid(Binder.getCallingUid()) |
| 2486 | .setMethod("requestCellInfoUpdate") |
| 2487 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2488 | .build()); |
| 2489 | switch (locationResult) { |
| 2490 | case DENIED_HARD: |
| 2491 | throw new SecurityException("Not allowed to access cell info"); |
| 2492 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2493 | try { |
| 2494 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2495 | } catch (RemoteException re) { |
| 2496 | // Drop without consequences |
| 2497 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2498 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2501 | |
| 2502 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2503 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2504 | |
| 2505 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2506 | } |
| 2507 | |
| 2508 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2509 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2510 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2511 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | |
| 2513 | final long identity = Binder.clearCallingIdentity(); |
| 2514 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2515 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2516 | } finally { |
| 2517 | Binder.restoreCallingIdentity(identity); |
| 2518 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2521 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2522 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2523 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2524 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2525 | return null; |
| 2526 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2527 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2528 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2529 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2530 | return null; |
| 2531 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2532 | |
| 2533 | final long identity = Binder.clearCallingIdentity(); |
| 2534 | try { |
| 2535 | return phone.getImei(); |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(identity); |
| 2538 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2542 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2543 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2544 | String tac = null; |
| 2545 | if (phone != null) { |
| 2546 | String imei = phone.getImei(); |
| 2547 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2548 | } |
| 2549 | return tac; |
| 2550 | } |
| 2551 | |
| 2552 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2553 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2554 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2555 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2556 | return null; |
| 2557 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2558 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2559 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2560 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2561 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2562 | return null; |
| 2563 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | |
| 2565 | final long identity = Binder.clearCallingIdentity(); |
| 2566 | try { |
| 2567 | return phone.getMeid(); |
| 2568 | } finally { |
| 2569 | Binder.restoreCallingIdentity(identity); |
| 2570 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2574 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2575 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2576 | String manufacturerCode = null; |
| 2577 | if (phone != null) { |
| 2578 | String meid = phone.getMeid(); |
| 2579 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2580 | } |
| 2581 | return manufacturerCode; |
| 2582 | } |
| 2583 | |
| 2584 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2585 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2586 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2587 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2588 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2589 | return null; |
| 2590 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2591 | int subId = phone.getSubId(); |
| 2592 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2593 | mApp, subId, callingPackage, callingFeatureId, |
| 2594 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2595 | return null; |
| 2596 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | |
| 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
| 2600 | return phone.getDeviceSvn(); |
| 2601 | } finally { |
| 2602 | Binder.restoreCallingIdentity(identity); |
| 2603 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2606 | @Override |
| 2607 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2608 | final long identity = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | final Phone phone = getPhone(subId); |
| 2611 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(identity); |
| 2614 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | @Override |
| 2618 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | final long identity = Binder.clearCallingIdentity(); |
| 2620 | try { |
| 2621 | final Phone phone = getPhone(subId); |
| 2622 | return phone == null ? null : phone.getCarrierName(); |
| 2623 | } finally { |
| 2624 | Binder.restoreCallingIdentity(identity); |
| 2625 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2626 | } |
| 2627 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2628 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2629 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2630 | final long identity = Binder.clearCallingIdentity(); |
| 2631 | try { |
| 2632 | final Phone phone = getPhone(subId); |
| 2633 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2634 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2635 | } finally { |
| 2636 | Binder.restoreCallingIdentity(identity); |
| 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2641 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2642 | final long identity = Binder.clearCallingIdentity(); |
| 2643 | try { |
| 2644 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2645 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2646 | } finally { |
| 2647 | Binder.restoreCallingIdentity(identity); |
| 2648 | } |
| 2649 | } |
| 2650 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2651 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2652 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2653 | if (!isSubscriptionMccMnc) { |
| 2654 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2655 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2656 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2657 | if (phone == null) { |
| 2658 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2659 | } |
| 2660 | final long identity = Binder.clearCallingIdentity(); |
| 2661 | try { |
| 2662 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2663 | } finally { |
| 2664 | Binder.restoreCallingIdentity(identity); |
| 2665 | } |
| 2666 | } |
| 2667 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | // |
| 2669 | // Internal helper methods. |
| 2670 | // |
| 2671 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2672 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2673 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2674 | * |
| 2675 | * @throws SecurityException if the caller does not have the required permission |
| 2676 | */ |
| 2677 | private void enforceModifyPermission() { |
| 2678 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2679 | } |
| 2680 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2681 | /** |
| 2682 | * Make sure the caller is system. |
| 2683 | * |
| 2684 | * @throws SecurityException if the caller is not system. |
| 2685 | */ |
| 2686 | private void enforceSystemCaller() { |
| 2687 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2688 | throw new SecurityException("Caller must be system"); |
| 2689 | } |
| 2690 | } |
| 2691 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2692 | private void enforceActiveEmergencySessionPermission() { |
| 2693 | mApp.enforceCallingOrSelfPermission( |
| 2694 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2695 | } |
| 2696 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | /** |
| 2698 | * Make sure the caller has the CALL_PHONE permission. |
| 2699 | * |
| 2700 | * @throws SecurityException if the caller does not have the required permission |
| 2701 | */ |
| 2702 | private void enforceCallPermission() { |
| 2703 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2704 | } |
| 2705 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2706 | private void enforceSettingsPermission() { |
| 2707 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2708 | } |
| 2709 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2710 | private String createTelUrl(String number) { |
| 2711 | if (TextUtils.isEmpty(number)) { |
| 2712 | return null; |
| 2713 | } |
| 2714 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2715 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2718 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2719 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2720 | } |
| 2721 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2722 | private static void logv(String msg) { |
| 2723 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2724 | } |
| 2725 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2726 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2728 | } |
| 2729 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2730 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2732 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2735 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2736 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2737 | final long identity = Binder.clearCallingIdentity(); |
| 2738 | try { |
| 2739 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2740 | if (phone == null) { |
| 2741 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2742 | } else { |
| 2743 | return phone.getPhoneType(); |
| 2744 | } |
| 2745 | } finally { |
| 2746 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2747 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | /** |
| 2751 | * Returns the CDMA ERI icon index to display |
| 2752 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2753 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2754 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2755 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2756 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2759 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2760 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2761 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2762 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2763 | mApp, subId, callingPackage, callingFeatureId, |
| 2764 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2765 | return -1; |
| 2766 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2767 | |
| 2768 | final long identity = Binder.clearCallingIdentity(); |
| 2769 | try { |
| 2770 | final Phone phone = getPhone(subId); |
| 2771 | if (phone != null) { |
| 2772 | return phone.getCdmaEriIconIndex(); |
| 2773 | } else { |
| 2774 | return -1; |
| 2775 | } |
| 2776 | } finally { |
| 2777 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2778 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | /** |
| 2782 | * Returns the CDMA ERI icon mode, |
| 2783 | * 0 - ON |
| 2784 | * 1 - FLASHING |
| 2785 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2786 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2787 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2788 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2789 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2792 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2793 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2794 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2795 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2796 | mApp, subId, callingPackage, callingFeatureId, |
| 2797 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2798 | return -1; |
| 2799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2800 | |
| 2801 | final long identity = Binder.clearCallingIdentity(); |
| 2802 | try { |
| 2803 | final Phone phone = getPhone(subId); |
| 2804 | if (phone != null) { |
| 2805 | return phone.getCdmaEriIconMode(); |
| 2806 | } else { |
| 2807 | return -1; |
| 2808 | } |
| 2809 | } finally { |
| 2810 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2811 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | /** |
| 2815 | * Returns the CDMA ERI text, |
| 2816 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2817 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2818 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2819 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2820 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2823 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2824 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2825 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2826 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2827 | mApp, subId, callingPackage, callingFeatureId, |
| 2828 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2829 | return null; |
| 2830 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2831 | |
| 2832 | final long identity = Binder.clearCallingIdentity(); |
| 2833 | try { |
| 2834 | final Phone phone = getPhone(subId); |
| 2835 | if (phone != null) { |
| 2836 | return phone.getCdmaEriText(); |
| 2837 | } else { |
| 2838 | return null; |
| 2839 | } |
| 2840 | } finally { |
| 2841 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2842 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2846 | * Returns the CDMA MDN. |
| 2847 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2848 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2849 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2850 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2851 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | |
| 2853 | final long identity = Binder.clearCallingIdentity(); |
| 2854 | try { |
| 2855 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2856 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2857 | return phone.getLine1Number(); |
| 2858 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2859 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2860 | return null; |
| 2861 | } |
| 2862 | } finally { |
| 2863 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | /** |
| 2868 | * Returns the CDMA MIN. |
| 2869 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2870 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2871 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2873 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2874 | |
| 2875 | final long identity = Binder.clearCallingIdentity(); |
| 2876 | try { |
| 2877 | final Phone phone = getPhone(subId); |
| 2878 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2879 | return phone.getCdmaMin(); |
| 2880 | } else { |
| 2881 | return null; |
| 2882 | } |
| 2883 | } finally { |
| 2884 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2885 | } |
| 2886 | } |
| 2887 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2888 | @Override |
| 2889 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2890 | INumberVerificationCallback callback, String callingPackage) { |
| 2891 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2892 | != PERMISSION_GRANTED) { |
| 2893 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2894 | } |
| 2895 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2896 | |
| 2897 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2898 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2899 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2900 | } |
| 2901 | |
| 2902 | if (range == null) { |
| 2903 | throw new NullPointerException("Range must be non-null"); |
| 2904 | } |
| 2905 | |
| 2906 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2907 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2908 | |
| 2909 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2910 | } |
| 2911 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2912 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2913 | * Returns true if CDMA provisioning needs to run. |
| 2914 | */ |
| 2915 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2916 | final long identity = Binder.clearCallingIdentity(); |
| 2917 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2918 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2919 | } finally { |
| 2920 | Binder.restoreCallingIdentity(identity); |
| 2921 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2925 | * Sets the voice mail number of a given subId. |
| 2926 | */ |
| 2927 | @Override |
| 2928 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2929 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2930 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2931 | |
| 2932 | final long identity = Binder.clearCallingIdentity(); |
| 2933 | try { |
| 2934 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2935 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2936 | return success; |
| 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(identity); |
| 2939 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2940 | } |
| 2941 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2942 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2943 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2944 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2945 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2946 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2947 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2948 | throw new SecurityException("caller must be system dialer"); |
| 2949 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2950 | |
| 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2954 | if (phoneAccountHandle == null) { |
| 2955 | return null; |
| 2956 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2957 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2958 | } finally { |
| 2959 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2960 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2964 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2965 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2966 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2967 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2968 | mApp, subId, callingPackage, callingFeatureId, |
| 2969 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2970 | return null; |
| 2971 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2972 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2973 | final long identity = Binder.clearCallingIdentity(); |
| 2974 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2975 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2976 | } finally { |
| 2977 | Binder.restoreCallingIdentity(identity); |
| 2978 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2982 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2983 | VisualVoicemailSmsFilterSettings settings) { |
| 2984 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2985 | |
| 2986 | final long identity = Binder.clearCallingIdentity(); |
| 2987 | try { |
| 2988 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2989 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(identity); |
| 2992 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2996 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2997 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | |
| 2999 | final long identity = Binder.clearCallingIdentity(); |
| 3000 | try { |
| 3001 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3002 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | } finally { |
| 3004 | Binder.restoreCallingIdentity(identity); |
| 3005 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3009 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3010 | String callingPackage, int subId) { |
| 3011 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3012 | |
| 3013 | final long identity = Binder.clearCallingIdentity(); |
| 3014 | try { |
| 3015 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3016 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(identity); |
| 3019 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3023 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3024 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3025 | |
| 3026 | final long identity = Binder.clearCallingIdentity(); |
| 3027 | try { |
| 3028 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3029 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
| 3032 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | @Override |
| 3036 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3037 | String number, int port, String text, PendingIntent sentIntent) { |
| 3038 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3039 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3040 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3041 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3042 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3043 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3044 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3045 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3046 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3047 | * Sets the voice activation state of a given subId. |
| 3048 | */ |
| 3049 | @Override |
| 3050 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3052 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3053 | |
| 3054 | final long identity = Binder.clearCallingIdentity(); |
| 3055 | try { |
| 3056 | final Phone phone = getPhone(subId); |
| 3057 | if (phone != null) { |
| 3058 | phone.setVoiceActivationState(activationState); |
| 3059 | } else { |
| 3060 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3061 | } |
| 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | /** |
| 3068 | * Sets the data activation state of a given subId. |
| 3069 | */ |
| 3070 | @Override |
| 3071 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3073 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3074 | |
| 3075 | final long identity = Binder.clearCallingIdentity(); |
| 3076 | try { |
| 3077 | final Phone phone = getPhone(subId); |
| 3078 | if (phone != null) { |
| 3079 | phone.setDataActivationState(activationState); |
| 3080 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3081 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | } |
| 3083 | } finally { |
| 3084 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | /** |
| 3089 | * Returns the voice activation state of a given subId. |
| 3090 | */ |
| 3091 | @Override |
| 3092 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3093 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3095 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3096 | final long identity = Binder.clearCallingIdentity(); |
| 3097 | try { |
| 3098 | if (phone != null) { |
| 3099 | return phone.getVoiceActivationState(); |
| 3100 | } else { |
| 3101 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3102 | } |
| 3103 | } finally { |
| 3104 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3105 | } |
| 3106 | } |
| 3107 | |
| 3108 | /** |
| 3109 | * Returns the data activation state of a given subId. |
| 3110 | */ |
| 3111 | @Override |
| 3112 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3113 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3114 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3115 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3116 | final long identity = Binder.clearCallingIdentity(); |
| 3117 | try { |
| 3118 | if (phone != null) { |
| 3119 | return phone.getDataActivationState(); |
| 3120 | } else { |
| 3121 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3122 | } |
| 3123 | } finally { |
| 3124 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3129 | * Returns the unread count of voicemails for a subId |
| 3130 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3131 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3132 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3133 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3134 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3135 | mApp, subId, callingPackage, callingFeatureId, |
| 3136 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3137 | return 0; |
| 3138 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3139 | final long identity = Binder.clearCallingIdentity(); |
| 3140 | try { |
| 3141 | final Phone phone = getPhone(subId); |
| 3142 | if (phone != null) { |
| 3143 | return phone.getVoiceMessageCount(); |
| 3144 | } else { |
| 3145 | return 0; |
| 3146 | } |
| 3147 | } finally { |
| 3148 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3149 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3153 | * returns true, if the device is in a state where both voice and data |
| 3154 | * are supported simultaneously. This can change based on location or network condition. |
| 3155 | */ |
| 3156 | @Override |
| 3157 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | final long identity = Binder.clearCallingIdentity(); |
| 3159 | try { |
| 3160 | final Phone phone = getPhone(subId); |
| 3161 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3162 | } finally { |
| 3163 | Binder.restoreCallingIdentity(identity); |
| 3164 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3168 | * Send the dialer code if called from the current default dialer or the caller has |
| 3169 | * carrier privilege. |
| 3170 | * @param inputCode The dialer code to send |
| 3171 | */ |
| 3172 | @Override |
| 3173 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3174 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3175 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3176 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3177 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3178 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3179 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3180 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3181 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3182 | |
| 3183 | final long identity = Binder.clearCallingIdentity(); |
| 3184 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3185 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3186 | } finally { |
| 3187 | Binder.restoreCallingIdentity(identity); |
| 3188 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3189 | } |
| 3190 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3191 | @Override |
| 3192 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3193 | TelephonyPermissions |
| 3194 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3195 | mApp, subId, "getNetworkSelectionMode"); |
| 3196 | final long identity = Binder.clearCallingIdentity(); |
| 3197 | try { |
| 3198 | if (!isActiveSubscription(subId)) { |
| 3199 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3200 | } |
| 3201 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3202 | } finally { |
| 3203 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3204 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3205 | } |
| 3206 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3207 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3208 | public boolean isInEmergencySmsMode() { |
| 3209 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
| 3212 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3213 | if (phone.isInEmergencySmsMode()) { |
| 3214 | return true; |
| 3215 | } |
| 3216 | } |
| 3217 | } finally { |
| 3218 | Binder.restoreCallingIdentity(identity); |
| 3219 | } |
| 3220 | return false; |
| 3221 | } |
| 3222 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3223 | /** |
| 3224 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3225 | * @param subId The subscription to use to check the configuration. |
| 3226 | * @param c The callback that will be used to send the result. |
| 3227 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3228 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3229 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3230 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3231 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3232 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3233 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3234 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3235 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3236 | "IMS not available on device."); |
| 3237 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3238 | final long token = Binder.clearCallingIdentity(); |
| 3239 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3240 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3241 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3242 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3243 | } catch (ImsException e) { |
| 3244 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3245 | } finally { |
| 3246 | Binder.restoreCallingIdentity(token); |
| 3247 | } |
| 3248 | } |
| 3249 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3250 | /** |
| 3251 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3252 | * @param subId The subscription to use to check the configuration. |
| 3253 | * @param c The callback that will be used to send the result. |
| 3254 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3255 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3256 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3257 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3258 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3259 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3260 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3261 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3262 | final long token = Binder.clearCallingIdentity(); |
| 3263 | try { |
| 3264 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3265 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3266 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3267 | } catch (ImsException e) { |
| 3268 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3269 | + "is inactive, ignoring unregister."); |
| 3270 | // If the subscription is no longer active, just return, since the callback |
| 3271 | // will already have been removed internally. |
| 3272 | } finally { |
| 3273 | Binder.restoreCallingIdentity(token); |
| 3274 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3277 | /** |
| 3278 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3279 | */ |
| 3280 | @Override |
| 3281 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3282 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3283 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3284 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3285 | "IMS not available on device."); |
| 3286 | } |
| 3287 | final long token = Binder.clearCallingIdentity(); |
| 3288 | try { |
| 3289 | Phone phone = getPhone(subId); |
| 3290 | if (phone == null) { |
| 3291 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3292 | + subId + "'"); |
| 3293 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3294 | } |
| 3295 | phone.getImsRegistrationState(regState -> { |
| 3296 | try { |
| 3297 | consumer.accept((regState == null) |
| 3298 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3299 | } catch (RemoteException e) { |
| 3300 | // Ignore if the remote process is no longer available to call back. |
| 3301 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3302 | } |
| 3303 | }); |
| 3304 | } finally { |
| 3305 | Binder.restoreCallingIdentity(token); |
| 3306 | } |
| 3307 | } |
| 3308 | |
| 3309 | /** |
| 3310 | * Get the transport type for the IMS service registration state. |
| 3311 | */ |
| 3312 | @Override |
| 3313 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3314 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3315 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3316 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3317 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3318 | "IMS not available on device."); |
| 3319 | } |
| 3320 | final long token = Binder.clearCallingIdentity(); |
| 3321 | try { |
| 3322 | Phone phone = getPhone(subId); |
| 3323 | if (phone == null) { |
| 3324 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3325 | + subId + "'"); |
| 3326 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3327 | } |
| 3328 | phone.getImsRegistrationTech(regTech -> { |
| 3329 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3330 | int regTechConverted = (regTech == null) |
| 3331 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3332 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3333 | regTechConverted); |
| 3334 | try { |
| 3335 | consumer.accept(regTechConverted); |
| 3336 | } catch (RemoteException e) { |
| 3337 | // Ignore if the remote process is no longer available to call back. |
| 3338 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3339 | } |
| 3340 | }); |
| 3341 | } finally { |
| 3342 | Binder.restoreCallingIdentity(token); |
| 3343 | } |
| 3344 | } |
| 3345 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3346 | /** |
| 3347 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3348 | * @param subId The subscription to use to check the configuration. |
| 3349 | * @param c The callback that will be used to send the result. |
| 3350 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3351 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3352 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3353 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3354 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3355 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3356 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3357 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3358 | "IMS not available on device."); |
| 3359 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3360 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3361 | final long token = Binder.clearCallingIdentity(); |
| 3362 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3363 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3364 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3365 | } catch (ImsException e) { |
| 3366 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3367 | } finally { |
| 3368 | Binder.restoreCallingIdentity(token); |
| 3369 | } |
| 3370 | } |
| 3371 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3372 | /** |
| 3373 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3374 | * @param subId The subscription to use to check the configuration. |
| 3375 | * @param c The callback that will be used to send the result. |
| 3376 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3377 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3378 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3379 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3380 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3381 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3382 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3383 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3384 | |
| 3385 | final long token = Binder.clearCallingIdentity(); |
| 3386 | try { |
| 3387 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3388 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3389 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3390 | } catch (ImsException e) { |
| 3391 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3392 | + "is inactive, ignoring unregister."); |
| 3393 | // If the subscription is no longer active, just return, since the callback |
| 3394 | // will already have been removed internally. |
| 3395 | } finally { |
| 3396 | Binder.restoreCallingIdentity(token); |
| 3397 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3401 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3402 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3403 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3404 | final long token = Binder.clearCallingIdentity(); |
| 3405 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3406 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3407 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3408 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3409 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3410 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3411 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3412 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3413 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3414 | } finally { |
| 3415 | Binder.restoreCallingIdentity(token); |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3420 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3421 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3422 | final long token = Binder.clearCallingIdentity(); |
| 3423 | try { |
| 3424 | Phone phone = getPhone(subId); |
| 3425 | if (phone == null) return false; |
| 3426 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3427 | } finally { |
| 3428 | Binder.restoreCallingIdentity(token); |
| 3429 | } |
| 3430 | } |
| 3431 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3432 | /** |
| 3433 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3434 | * subscription. |
| 3435 | * @param subId The subscription to use to check the configuration. |
| 3436 | * @param callback The callback that will be used to send the result. |
| 3437 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3438 | * @param transportType The transport type of the MmTelFeature capability. |
| 3439 | */ |
| 3440 | @Override |
| 3441 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3442 | int transportType) { |
| 3443 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3444 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3445 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3446 | "IMS not available on device."); |
| 3447 | } |
| 3448 | final long token = Binder.clearCallingIdentity(); |
| 3449 | try { |
| 3450 | int slotId = getSlotIndex(subId); |
| 3451 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3452 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3453 | + subId + "'"); |
| 3454 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3455 | } |
| 3456 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3457 | transportType, aBoolean -> { |
| 3458 | try { |
| 3459 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3460 | } catch (RemoteException e) { |
| 3461 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3462 | + "running. Ignore"); |
| 3463 | } |
| 3464 | }); |
| 3465 | } finally { |
| 3466 | Binder.restoreCallingIdentity(token); |
| 3467 | } |
| 3468 | } |
| 3469 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3470 | /** |
| 3471 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3472 | * @param subId The subscription to use to check the configuration. |
| 3473 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3474 | @Override |
| 3475 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3476 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3477 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3478 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3479 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3480 | final long token = Binder.clearCallingIdentity(); |
| 3481 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3482 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3483 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3484 | } catch (ImsException e) { |
| 3485 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3486 | } finally { |
| 3487 | Binder.restoreCallingIdentity(token); |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3492 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3494 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3495 | final long identity = Binder.clearCallingIdentity(); |
| 3496 | try { |
| 3497 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3498 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3499 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3500 | } catch (ImsException e) { |
| 3501 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3502 | } finally { |
| 3503 | Binder.restoreCallingIdentity(identity); |
| 3504 | } |
| 3505 | } |
| 3506 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3507 | /** |
| 3508 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3509 | * @param subId The subscription to use to check the configuration. |
| 3510 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3511 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3512 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3513 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3514 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3515 | final long identity = Binder.clearCallingIdentity(); |
| 3516 | try { |
| 3517 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3518 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3519 | } catch (ImsException e) { |
| 3520 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3521 | } finally { |
| 3522 | Binder.restoreCallingIdentity(identity); |
| 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3527 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3529 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3533 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3534 | } catch (ImsException e) { |
| 3535 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3536 | } finally { |
| 3537 | Binder.restoreCallingIdentity(identity); |
| 3538 | } |
| 3539 | } |
| 3540 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3541 | /** |
| 3542 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3543 | * @param subId The subscription to use to check the configuration. |
| 3544 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3545 | @Override |
| 3546 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3547 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3548 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3549 | final long identity = Binder.clearCallingIdentity(); |
| 3550 | try { |
| 3551 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3552 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3553 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3554 | } catch (ImsException e) { |
| 3555 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3556 | } finally { |
| 3557 | Binder.restoreCallingIdentity(identity); |
| 3558 | } |
| 3559 | } |
| 3560 | |
| 3561 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3562 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3564 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3565 | final long identity = Binder.clearCallingIdentity(); |
| 3566 | try { |
| 3567 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3568 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3569 | } catch (ImsException e) { |
| 3570 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3571 | } finally { |
| 3572 | Binder.restoreCallingIdentity(identity); |
| 3573 | } |
| 3574 | } |
| 3575 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3576 | /** |
| 3577 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3578 | * @param subId The subscription to use to check the configuration. |
| 3579 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3580 | @Override |
| 3581 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3582 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3583 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3584 | final long identity = Binder.clearCallingIdentity(); |
| 3585 | try { |
| 3586 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3587 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3588 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3589 | } catch (ImsException e) { |
| 3590 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3591 | } finally { |
| 3592 | Binder.restoreCallingIdentity(identity); |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3597 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3598 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3599 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3603 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3604 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3605 | } catch (ImsException e) { |
| 3606 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3607 | } finally { |
| 3608 | Binder.restoreCallingIdentity(identity); |
| 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | @Override |
| 3613 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3615 | "setVoWiFiNonPersistent"); |
| 3616 | final long identity = Binder.clearCallingIdentity(); |
| 3617 | try { |
| 3618 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3619 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3620 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3621 | } catch (ImsException e) { |
| 3622 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3623 | } finally { |
| 3624 | Binder.restoreCallingIdentity(identity); |
| 3625 | } |
| 3626 | } |
| 3627 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3628 | /** |
| 3629 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3630 | * @param subId The subscription to use to check the configuration. |
| 3631 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3632 | @Override |
| 3633 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3634 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3635 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3636 | final long identity = Binder.clearCallingIdentity(); |
| 3637 | try { |
| 3638 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3639 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3640 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3641 | } catch (ImsException e) { |
| 3642 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3643 | } finally { |
| 3644 | Binder.restoreCallingIdentity(identity); |
| 3645 | } |
| 3646 | } |
| 3647 | |
| 3648 | @Override |
| 3649 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3651 | "setVoWiFiModeSetting"); |
| 3652 | final long identity = Binder.clearCallingIdentity(); |
| 3653 | try { |
| 3654 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3655 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3656 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3657 | } catch (ImsException e) { |
| 3658 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3659 | } finally { |
| 3660 | Binder.restoreCallingIdentity(identity); |
| 3661 | } |
| 3662 | } |
| 3663 | |
| 3664 | @Override |
| 3665 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3666 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3667 | final long identity = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3670 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3671 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3672 | } catch (ImsException e) { |
| 3673 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3674 | } finally { |
| 3675 | Binder.restoreCallingIdentity(identity); |
| 3676 | } |
| 3677 | } |
| 3678 | |
| 3679 | @Override |
| 3680 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3681 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3682 | "setVoWiFiRoamingModeSetting"); |
| 3683 | final long identity = Binder.clearCallingIdentity(); |
| 3684 | try { |
| 3685 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3686 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3687 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3688 | } catch (ImsException e) { |
| 3689 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(identity); |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | @Override |
| 3696 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3697 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3698 | "setRttCapabilityEnabled"); |
| 3699 | final long identity = Binder.clearCallingIdentity(); |
| 3700 | try { |
| 3701 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3702 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3703 | } catch (ImsException e) { |
| 3704 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3705 | } finally { |
| 3706 | Binder.restoreCallingIdentity(identity); |
| 3707 | } |
| 3708 | } |
| 3709 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3710 | /** |
| 3711 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3712 | * @param subId The subscription to use to check the configuration. |
| 3713 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3714 | @Override |
| 3715 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3716 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3717 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3718 | final long identity = Binder.clearCallingIdentity(); |
| 3719 | try { |
| 3720 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3721 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3722 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3723 | } catch (ImsException e) { |
| 3724 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
| 3727 | } |
| 3728 | } |
| 3729 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3730 | @Override |
| 3731 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3732 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3733 | final long identity = Binder.clearCallingIdentity(); |
| 3734 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3735 | if (!isImsAvailableOnDevice()) { |
| 3736 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3737 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3738 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3739 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3740 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3741 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3742 | } catch (ImsException e) { |
| 3743 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3744 | } finally { |
| 3745 | Binder.restoreCallingIdentity(identity); |
| 3746 | } |
| 3747 | } |
| 3748 | |
| 3749 | @Override |
| 3750 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3751 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3752 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3753 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3754 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3755 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3756 | try { |
| 3757 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3758 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3759 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3760 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3761 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3762 | + "is inactive, ignoring unregister."); |
| 3763 | // If the subscription is no longer active, just return, since the callback will already |
| 3764 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3765 | } finally { |
| 3766 | Binder.restoreCallingIdentity(identity); |
| 3767 | } |
| 3768 | } |
| 3769 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3770 | |
| 3771 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3773 | message); |
| 3774 | } |
| 3775 | |
| 3776 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3777 | boolean isMmtelCapability) { |
| 3778 | Phone phone = getPhone(subId); |
| 3779 | if (phone == null) { |
| 3780 | loge("phone instance null for subid " + subId); |
| 3781 | return false; |
| 3782 | } |
| 3783 | if (isMmtelCapability) { |
| 3784 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3785 | return false; |
| 3786 | } |
| 3787 | } else { |
| 3788 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3789 | return false; |
| 3790 | } |
| 3791 | } |
| 3792 | return true; |
| 3793 | } |
| 3794 | |
| 3795 | @Override |
| 3796 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3797 | boolean isProvisioned) { |
| 3798 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3799 | |
| 3800 | final long identity = Binder.clearCallingIdentity(); |
| 3801 | try { |
| 3802 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3803 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3804 | return; |
| 3805 | } |
| 3806 | |
| 3807 | // this capability requires provisioning, route to the correct API. |
| 3808 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3809 | switch (capability) { |
| 3810 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3811 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3812 | ims.setEabProvisioned(isProvisioned); |
| 3813 | break; |
| 3814 | default: { |
| 3815 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3816 | + "rcs capability '" + capability + "', which does not require " |
| 3817 | + "provisioning."); |
| 3818 | } |
| 3819 | } |
| 3820 | } finally { |
| 3821 | Binder.restoreCallingIdentity(identity); |
| 3822 | } |
| 3823 | |
| 3824 | } |
| 3825 | |
| 3826 | |
| 3827 | @Override |
| 3828 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3829 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3830 | final long identity = Binder.clearCallingIdentity(); |
| 3831 | try { |
| 3832 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3833 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3834 | return true; |
| 3835 | } |
| 3836 | |
| 3837 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3838 | switch (capability) { |
| 3839 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3840 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3841 | return ims.isEabProvisionedOnDevice(); |
| 3842 | |
| 3843 | default: { |
| 3844 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3845 | + "capability '" + capability + "', which does not require " |
| 3846 | + "provisioning."); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | } finally { |
| 3851 | Binder.restoreCallingIdentity(identity); |
| 3852 | } |
| 3853 | } |
| 3854 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3855 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3856 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3857 | boolean isProvisioned) { |
| 3858 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3859 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3860 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3861 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3862 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3863 | final long identity = Binder.clearCallingIdentity(); |
| 3864 | try { |
| 3865 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3866 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3867 | return; |
| 3868 | } |
| 3869 | |
| 3870 | // this capability requires provisioning, route to the correct API. |
| 3871 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3872 | switch (capability) { |
| 3873 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3874 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3875 | ims.setVolteProvisioned(isProvisioned); |
| 3876 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3877 | ims.setWfcProvisioned(isProvisioned); |
| 3878 | } |
| 3879 | break; |
| 3880 | } |
| 3881 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3882 | // There is currently no difference in VT provisioning type. |
| 3883 | ims.setVtProvisioned(isProvisioned); |
| 3884 | break; |
| 3885 | } |
| 3886 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3887 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3888 | // change the capability of the feature instead if needed. |
| 3889 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3890 | == isProvisioned) { |
| 3891 | // No change in provisioning. |
| 3892 | return; |
| 3893 | } |
| 3894 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3895 | try { |
| 3896 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3897 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3898 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3899 | + ", Exception" + e.getMessage()); |
| 3900 | } |
| 3901 | break; |
| 3902 | } |
| 3903 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3904 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3905 | + "MmTel capability '" + capability + "', which does not require " |
| 3906 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | } finally { |
| 3911 | Binder.restoreCallingIdentity(identity); |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | @Override |
| 3916 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3917 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3918 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3919 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3920 | } |
| 3921 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3922 | final long identity = Binder.clearCallingIdentity(); |
| 3923 | try { |
| 3924 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3925 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3926 | return true; |
| 3927 | } |
| 3928 | |
| 3929 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3930 | switch (capability) { |
| 3931 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3932 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3933 | return ims.isVolteProvisionedOnDevice(); |
| 3934 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3935 | return ims.isWfcProvisionedOnDevice(); |
| 3936 | } |
| 3937 | // This should never happen, since we are checking tech above to make sure it |
| 3938 | // is either LTE or IWLAN. |
| 3939 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3940 | + "capability."); |
| 3941 | } |
| 3942 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3943 | // There is currently no difference in VT provisioning type. |
| 3944 | return ims.isVtProvisionedOnDevice(); |
| 3945 | } |
| 3946 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3947 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3948 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3949 | } |
| 3950 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3951 | throw new IllegalArgumentException( |
| 3952 | "Tried to get provisioning for MmTel capability '" + capability |
| 3953 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | } finally { |
| 3958 | Binder.restoreCallingIdentity(identity); |
| 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | @Override |
| 3963 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3964 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3965 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3966 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3967 | } |
| 3968 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3969 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3970 | return (provisionedBits & capability) > 0; |
| 3971 | } |
| 3972 | |
| 3973 | @Override |
| 3974 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3975 | boolean isProvisioned) { |
| 3976 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3977 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3978 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3979 | } |
| 3980 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3981 | "setProvisioningStatusForCapability"); |
| 3982 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3983 | // If the current provisioning status for capability already matches isProvisioned, |
| 3984 | // do nothing. |
| 3985 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3986 | return; |
| 3987 | } |
| 3988 | if (isProvisioned) { |
| 3989 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3990 | } else { |
| 3991 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3992 | } |
| 3993 | } |
| 3994 | |
| 3995 | /** |
| 3996 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3997 | * technology. The bitfield should mirror the bitfield defined by |
| 3998 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3999 | */ |
| 4000 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4001 | String key = getMmTelProvisioningKey(subId, tech); |
| 4002 | // Default is no capabilities are provisioned. |
| 4003 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4004 | } |
| 4005 | |
| 4006 | /** |
| 4007 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4008 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4009 | * technology specified. |
| 4010 | * |
| 4011 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4012 | */ |
| 4013 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4014 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4015 | String key = getMmTelProvisioningKey(subId, tech); |
| 4016 | editor.putInt(key, newField); |
| 4017 | editor.commit(); |
| 4018 | } |
| 4019 | |
| 4020 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4021 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4022 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4023 | } |
| 4024 | |
| 4025 | /** |
| 4026 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4027 | * carrier associated with the subscription id. |
| 4028 | */ |
| 4029 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4030 | int capability) { |
| 4031 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4032 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4033 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4034 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4035 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4036 | false); |
| 4037 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4038 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4039 | |
| 4040 | // First check to make sure that the capability requires provisioning. |
| 4041 | switch (capability) { |
| 4042 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4043 | // intentional fallthrough |
| 4044 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4045 | if (requireVoiceVtProvisioning) { |
| 4046 | // Voice and Video requires provisioning |
| 4047 | return true; |
| 4048 | } |
| 4049 | break; |
| 4050 | } |
| 4051 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4052 | if (requireUtProvisioning) { |
| 4053 | // UT requires provisioning |
| 4054 | return true; |
| 4055 | } |
| 4056 | break; |
| 4057 | } |
| 4058 | } |
| 4059 | return false; |
| 4060 | } |
| 4061 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4062 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4063 | int capability) { |
| 4064 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4065 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4066 | |
| 4067 | boolean requireRcsProvisioning = c.getBoolean( |
| 4068 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4069 | |
| 4070 | // First check to make sure that the capability requires provisioning. |
| 4071 | switch (capability) { |
| 4072 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4073 | // intentional fallthrough |
| 4074 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4075 | if (requireRcsProvisioning) { |
| 4076 | // OPTION or PRESENCE requires provisioning |
| 4077 | return true; |
| 4078 | } |
| 4079 | break; |
| 4080 | } |
| 4081 | } |
| 4082 | return false; |
| 4083 | } |
| 4084 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4085 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4086 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4087 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4088 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4089 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4090 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4091 | final long identity = Binder.clearCallingIdentity(); |
| 4092 | try { |
| 4093 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4094 | int slotId = getSlotIndex(subId); |
| 4095 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4096 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4097 | + subId + "' for key:" + key); |
| 4098 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4099 | } |
| 4100 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4101 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4102 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4103 | + subId + "' for key:" + key); |
| 4104 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4105 | } finally { |
| 4106 | Binder.restoreCallingIdentity(identity); |
| 4107 | } |
| 4108 | } |
| 4109 | |
| 4110 | @Override |
| 4111 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4112 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4113 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4114 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4115 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4116 | final long identity = Binder.clearCallingIdentity(); |
| 4117 | try { |
| 4118 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4119 | int slotId = getSlotIndex(subId); |
| 4120 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4121 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4122 | + subId + "' for key:" + key); |
| 4123 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4124 | } |
| 4125 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4126 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4127 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4128 | + subId + "' for key:" + key); |
| 4129 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(identity); |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | @Override |
| 4136 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4137 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4138 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4139 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4141 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4142 | final long identity = Binder.clearCallingIdentity(); |
| 4143 | try { |
| 4144 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4145 | int slotId = getSlotIndex(subId); |
| 4146 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4147 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4148 | + subId + "' for key:" + key); |
| 4149 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4150 | } |
| 4151 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4152 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4153 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4154 | + "' for key:" + key); |
| 4155 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4156 | } finally { |
| 4157 | Binder.restoreCallingIdentity(identity); |
| 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | @Override |
| 4162 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4163 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4164 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4165 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4167 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4168 | final long identity = Binder.clearCallingIdentity(); |
| 4169 | try { |
| 4170 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4171 | int slotId = getSlotIndex(subId); |
| 4172 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4173 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4174 | + subId + "' for key:" + key); |
| 4175 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4176 | } |
| 4177 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4178 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4179 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4180 | + "' for key:" + key); |
| 4181 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4182 | } finally { |
| 4183 | Binder.restoreCallingIdentity(identity); |
| 4184 | } |
| 4185 | } |
| 4186 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4187 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4188 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4189 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4190 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4191 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4192 | } |
| 4193 | return slotId; |
| 4194 | } |
| 4195 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4196 | private int getSlotIndex(int subId) { |
| 4197 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4198 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4199 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4200 | } |
| 4201 | return slotId; |
| 4202 | } |
| 4203 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4204 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4205 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4206 | */ |
| 4207 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4208 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4209 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4210 | final int targetSdk = getTargetSdk(callingPackage); |
| 4211 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4212 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4213 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4214 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4215 | mApp, subId, callingPackage, callingFeatureId, |
| 4216 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4217 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4218 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4219 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4220 | final long identity = Binder.clearCallingIdentity(); |
| 4221 | try { |
| 4222 | final Phone phone = getPhone(subId); |
| 4223 | if (phone != null) { |
| 4224 | return phone.getServiceState().getDataNetworkType(); |
| 4225 | } else { |
| 4226 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4227 | } |
| 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4230 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | /** |
| 4234 | * Returns the data network type |
| 4235 | */ |
| 4236 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4237 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4238 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4239 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | /** |
| 4243 | * Returns the data network type for a subId |
| 4244 | */ |
| 4245 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4246 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4247 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4248 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4249 | mApp, subId, callingPackage, callingFeatureId, |
| 4250 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4251 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4252 | } |
| 4253 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | final long identity = Binder.clearCallingIdentity(); |
| 4255 | try { |
| 4256 | final Phone phone = getPhone(subId); |
| 4257 | if (phone != null) { |
| 4258 | return phone.getServiceState().getDataNetworkType(); |
| 4259 | } else { |
| 4260 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4261 | } |
| 4262 | } finally { |
| 4263 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4264 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4268 | * Returns the Voice network type for a subId |
| 4269 | */ |
| 4270 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4271 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4272 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4273 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4274 | mApp, subId, callingPackage, callingFeatureId, |
| 4275 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4276 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4277 | } |
| 4278 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4279 | final long identity = Binder.clearCallingIdentity(); |
| 4280 | try { |
| 4281 | final Phone phone = getPhone(subId); |
| 4282 | if (phone != null) { |
| 4283 | return phone.getServiceState().getVoiceNetworkType(); |
| 4284 | } else { |
| 4285 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4286 | } |
| 4287 | } finally { |
| 4288 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4289 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | /** |
| 4293 | * @return true if a ICC card is present |
| 4294 | */ |
| 4295 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4296 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4297 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4298 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4302 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4303 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4304 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4305 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4306 | final long identity = Binder.clearCallingIdentity(); |
| 4307 | try { |
| 4308 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4309 | if (phone != null) { |
| 4310 | return phone.getIccCard().hasIccCard(); |
| 4311 | } else { |
| 4312 | return false; |
| 4313 | } |
| 4314 | } finally { |
| 4315 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4316 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | /** |
| 4320 | * Return if the current radio is LTE on CDMA. This |
| 4321 | * is a tri-state return value as for a period of time |
| 4322 | * the mode may be unknown. |
| 4323 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4324 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4325 | * @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] | 4326 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4327 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4328 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4329 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4330 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4331 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4334 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4335 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4336 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4337 | try { |
| 4338 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4339 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4340 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4341 | } |
| 4342 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4343 | final long identity = Binder.clearCallingIdentity(); |
| 4344 | try { |
| 4345 | final Phone phone = getPhone(subId); |
| 4346 | if (phone == null) { |
| 4347 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4348 | } else { |
| 4349 | return phone.getLteOnCdmaMode(); |
| 4350 | } |
| 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4353 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4354 | } |
| 4355 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4356 | /** |
| 4357 | * {@hide} |
| 4358 | * Returns Default subId, 0 in the case of single standby. |
| 4359 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4360 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4361 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4364 | private int getSlotForDefaultSubscription() { |
| 4365 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4366 | } |
| 4367 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4368 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4369 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4370 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4371 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4372 | private boolean isActiveSubscription(int subId) { |
| 4373 | return mSubscriptionController.isActiveSubId(subId); |
| 4374 | } |
| 4375 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4376 | /** |
| 4377 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4378 | */ |
| 4379 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4380 | final long identity = Binder.clearCallingIdentity(); |
| 4381 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4382 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4383 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4384 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4385 | } finally { |
| 4386 | Binder.restoreCallingIdentity(identity); |
| 4387 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | /** |
| 4391 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4392 | */ |
| 4393 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4394 | final long identity = Binder.clearCallingIdentity(); |
| 4395 | try { |
| 4396 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4397 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4398 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4399 | } finally { |
| 4400 | Binder.restoreCallingIdentity(identity); |
| 4401 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4402 | } |
| 4403 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4404 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4405 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4406 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4407 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4408 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4409 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4410 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4411 | if (phoneId == -1) { |
| 4412 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4413 | + " does not correspond to an active phone"); |
| 4414 | } |
| 4415 | return PhoneFactory.getPhone(phoneId); |
| 4416 | } |
| 4417 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4418 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4419 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4420 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4422 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4423 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4424 | if (DBG) { |
| 4425 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4426 | } |
| 4427 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4428 | p2); |
| 4429 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4430 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4431 | |
| 4432 | @Override |
| 4433 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4434 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4435 | enforceModifyPermission(); |
| 4436 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4437 | if (DBG) { |
| 4438 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4439 | } |
| 4440 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4441 | callingPackage, aid, p2); |
| 4442 | } |
| 4443 | |
| 4444 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4445 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4446 | final long identity = Binder.clearCallingIdentity(); |
| 4447 | try { |
| 4448 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4449 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4450 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4451 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4452 | if (bestComponent == null |
| 4453 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4454 | loge("The calling package is not allowed to access ISD-R."); |
| 4455 | throw new SecurityException( |
| 4456 | "The calling package is not allowed to access ISD-R."); |
| 4457 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4458 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4459 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4460 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4461 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4462 | null /* workSource */); |
| 4463 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4464 | return response; |
| 4465 | } finally { |
| 4466 | Binder.restoreCallingIdentity(identity); |
| 4467 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4471 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4472 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4473 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4474 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4475 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4476 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4477 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4478 | @Override |
| 4479 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4480 | enforceModifyPermission(); |
| 4481 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4482 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4483 | channel); |
| 4484 | } |
| 4485 | |
| 4486 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4487 | final long identity = Binder.clearCallingIdentity(); |
| 4488 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4489 | if (channel < 0) { |
| 4490 | return false; |
| 4491 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4492 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4493 | null /* workSource */); |
| 4494 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4495 | return success; |
| 4496 | } finally { |
| 4497 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4498 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4502 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4503 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4504 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4505 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4506 | if (DBG) { |
| 4507 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4508 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4509 | + p3 + " data=" + data); |
| 4510 | } |
| 4511 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4512 | command, p1, p2, p3, data); |
| 4513 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4514 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4515 | @Override |
| 4516 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4517 | int command, int p1, int p2, int p3, String data) { |
| 4518 | enforceModifyPermission(); |
| 4519 | if (DBG) { |
| 4520 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4521 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4522 | + p3 + " data=" + data); |
| 4523 | } |
| 4524 | return iccTransmitApduLogicalChannelWithPermission( |
| 4525 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4526 | data); |
| 4527 | } |
| 4528 | |
| 4529 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4530 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4531 | final long identity = Binder.clearCallingIdentity(); |
| 4532 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4533 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4534 | return ""; |
| 4535 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4537 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4538 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4539 | null /* workSource */); |
| 4540 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4541 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4542 | // Append the returned status code to the end of the response payload. |
| 4543 | String s = Integer.toHexString( |
| 4544 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4545 | if (response.payload != null) { |
| 4546 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4547 | } |
| 4548 | return s; |
| 4549 | } finally { |
| 4550 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4551 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4552 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4553 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4554 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4555 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4556 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4558 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4559 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4560 | if (DBG) { |
| 4561 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4562 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4563 | } |
| 4564 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4565 | cla, command, p1, p2, p3, data); |
| 4566 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4567 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4568 | @Override |
| 4569 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4570 | int command, int p1, int p2, int p3, String data) { |
| 4571 | enforceModifyPermission(); |
| 4572 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4573 | if (DBG) { |
| 4574 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4575 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4576 | + " data=" + data); |
| 4577 | } |
| 4578 | |
| 4579 | return iccTransmitApduBasicChannelWithPermission( |
| 4580 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4581 | p2, p3, data); |
| 4582 | } |
| 4583 | |
| 4584 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4585 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4586 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4587 | final long identity = Binder.clearCallingIdentity(); |
| 4588 | try { |
| 4589 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4590 | && TextUtils.equals(ISDR_AID, data)) { |
| 4591 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4592 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4593 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4594 | if (bestComponent == null |
| 4595 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4596 | loge("The calling package is not allowed to select ISD-R."); |
| 4597 | throw new SecurityException( |
| 4598 | "The calling package is not allowed to select ISD-R."); |
| 4599 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4600 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4602 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4603 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4604 | null /* workSource */); |
| 4605 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4607 | // Append the returned status code to the end of the response payload. |
| 4608 | String s = Integer.toHexString( |
| 4609 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4610 | if (response.payload != null) { |
| 4611 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4612 | } |
| 4613 | return s; |
| 4614 | } finally { |
| 4615 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4616 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4620 | 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] | 4621 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4622 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4623 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4624 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4625 | final long identity = Binder.clearCallingIdentity(); |
| 4626 | try { |
| 4627 | if (DBG) { |
| 4628 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4629 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4630 | } |
| 4631 | |
| 4632 | IccIoResult response = |
| 4633 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4634 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4635 | subId); |
| 4636 | |
| 4637 | if (DBG) { |
| 4638 | log("Exchange SIM_IO [R]" + response); |
| 4639 | } |
| 4640 | |
| 4641 | byte[] result = null; |
| 4642 | int length = 2; |
| 4643 | if (response.payload != null) { |
| 4644 | length = 2 + response.payload.length; |
| 4645 | result = new byte[length]; |
| 4646 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4647 | } else { |
| 4648 | result = new byte[length]; |
| 4649 | } |
| 4650 | |
| 4651 | result[length - 1] = (byte) response.sw2; |
| 4652 | result[length - 2] = (byte) response.sw1; |
| 4653 | return result; |
| 4654 | } finally { |
| 4655 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4656 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4657 | } |
| 4658 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4659 | /** |
| 4660 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4661 | * on a particular subscription |
| 4662 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4663 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4664 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4665 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4666 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4667 | return null; |
| 4668 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4669 | |
| 4670 | final long identity = Binder.clearCallingIdentity(); |
| 4671 | try { |
| 4672 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4673 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4674 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4675 | return null; |
| 4676 | } |
| 4677 | Object response = sendRequest( |
| 4678 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4679 | if (response instanceof String[]) { |
| 4680 | return (String[]) response; |
| 4681 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4682 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4684 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4685 | } finally { |
| 4686 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4687 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4688 | } |
| 4689 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4690 | /** |
| 4691 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4692 | * subscription. |
| 4693 | * |
| 4694 | * @param subId the id of the subscription. |
| 4695 | * @param appType the uicc app type, must be USIM or SIM. |
| 4696 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4697 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4698 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4699 | * @return number of fplmns that is successfully written to the SIM. |
| 4700 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4701 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4702 | String callingFeatureId) { |
| 4703 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4704 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4705 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4706 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4707 | } |
| 4708 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4709 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4710 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4711 | } |
| 4712 | if (fplmns == null) { |
| 4713 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4714 | } |
| 4715 | for (String fplmn : fplmns) { |
| 4716 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4717 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4718 | } |
| 4719 | } |
| 4720 | final long identity = Binder.clearCallingIdentity(); |
| 4721 | try { |
| 4722 | Object response = sendRequest( |
| 4723 | CMD_SET_FORBIDDEN_PLMNS, |
| 4724 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4725 | subId); |
| 4726 | return (int) response; |
| 4727 | } finally { |
| 4728 | Binder.restoreCallingIdentity(identity); |
| 4729 | } |
| 4730 | } |
| 4731 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4732 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4733 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4735 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4736 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4737 | final long identity = Binder.clearCallingIdentity(); |
| 4738 | try { |
| 4739 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4740 | if (response.payload == null) { |
| 4741 | return ""; |
| 4742 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4743 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4744 | // Append the returned status code to the end of the response payload. |
| 4745 | String s = Integer.toHexString( |
| 4746 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4747 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4748 | return s; |
| 4749 | } finally { |
| 4750 | Binder.restoreCallingIdentity(identity); |
| 4751 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4752 | } |
| 4753 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4754 | /** |
| 4755 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4756 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4757 | * |
| 4758 | * @param itemID the ID of the item to read |
| 4759 | * @return the NV item as a String, or null on error. |
| 4760 | */ |
| 4761 | @Override |
| 4762 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4763 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4764 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4765 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4766 | |
| 4767 | final long identity = Binder.clearCallingIdentity(); |
| 4768 | try { |
| 4769 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4770 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4772 | return value; |
| 4773 | } finally { |
| 4774 | Binder.restoreCallingIdentity(identity); |
| 4775 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | /** |
| 4779 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4780 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4781 | * |
| 4782 | * @param itemID the ID of the item to read |
| 4783 | * @param itemValue the value to write, as a String |
| 4784 | * @return true on success; false on any failure |
| 4785 | */ |
| 4786 | @Override |
| 4787 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4788 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4789 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4790 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4791 | |
| 4792 | final long identity = Binder.clearCallingIdentity(); |
| 4793 | try { |
| 4794 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4795 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4796 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4797 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4798 | return success; |
| 4799 | } finally { |
| 4800 | Binder.restoreCallingIdentity(identity); |
| 4801 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4802 | } |
| 4803 | |
| 4804 | /** |
| 4805 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4806 | * Used for device configuration by some CDMA operators. |
| 4807 | * |
| 4808 | * @param preferredRoamingList byte array containing the new PRL |
| 4809 | * @return true on success; false on any failure |
| 4810 | */ |
| 4811 | @Override |
| 4812 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4814 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4815 | |
| 4816 | final long identity = Binder.clearCallingIdentity(); |
| 4817 | try { |
| 4818 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4819 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4820 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4821 | return success; |
| 4822 | } finally { |
| 4823 | Binder.restoreCallingIdentity(identity); |
| 4824 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4828 | * 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] | 4829 | * Used for device configuration by some CDMA operators. |
| 4830 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4831 | * @param slotIndex - device slot. |
| 4832 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4833 | * @return true on success; false on any failure |
| 4834 | */ |
| 4835 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4836 | public boolean resetModemConfig(int slotIndex) { |
| 4837 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4838 | if (phone != null) { |
| 4839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4840 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4841 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4842 | final long identity = Binder.clearCallingIdentity(); |
| 4843 | try { |
| 4844 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4845 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4846 | return success; |
| 4847 | } finally { |
| 4848 | Binder.restoreCallingIdentity(identity); |
| 4849 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4850 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4851 | return false; |
| 4852 | } |
| 4853 | |
| 4854 | /** |
| 4855 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4856 | * |
| 4857 | * @param slotIndex - device slot. |
| 4858 | * |
| 4859 | * @return true on success; false on any failure |
| 4860 | */ |
| 4861 | @Override |
| 4862 | public boolean rebootModem(int slotIndex) { |
| 4863 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4864 | if (phone != null) { |
| 4865 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4866 | mApp, phone.getSubId(), "rebootModem"); |
| 4867 | |
| 4868 | final long identity = Binder.clearCallingIdentity(); |
| 4869 | try { |
| 4870 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4871 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4872 | return success; |
| 4873 | } finally { |
| 4874 | Binder.restoreCallingIdentity(identity); |
| 4875 | } |
| 4876 | } |
| 4877 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4878 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4879 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4880 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4881 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4882 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4883 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4884 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4885 | return new String[0]; |
| 4886 | } |
| 4887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4890 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4891 | } finally { |
| 4892 | Binder.restoreCallingIdentity(identity); |
| 4893 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4894 | } |
| 4895 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4896 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4897 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4898 | * {@link #disableIms(int)}. |
| 4899 | * @param slotIndex device slot. |
| 4900 | */ |
| 4901 | public void resetIms(int slotIndex) { |
| 4902 | enforceModifyPermission(); |
| 4903 | |
| 4904 | final long identity = Binder.clearCallingIdentity(); |
| 4905 | try { |
| 4906 | if (mImsResolver == null) { |
| 4907 | // may happen if the does not support IMS. |
| 4908 | return; |
| 4909 | } |
| 4910 | mImsResolver.disableIms(slotIndex); |
| 4911 | mImsResolver.enableIms(slotIndex); |
| 4912 | } finally { |
| 4913 | Binder.restoreCallingIdentity(identity); |
| 4914 | } |
| 4915 | } |
| 4916 | |
| 4917 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4918 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4919 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4920 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4921 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4922 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4923 | |
| 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4926 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4927 | // may happen if the device does not support IMS. |
| 4928 | return; |
| 4929 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4930 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | } finally { |
| 4932 | Binder.restoreCallingIdentity(identity); |
| 4933 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4937 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4938 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4939 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4940 | public void disableIms(int slotId) { |
| 4941 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4942 | |
| 4943 | final long identity = Binder.clearCallingIdentity(); |
| 4944 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4945 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4946 | // may happen if the device does not support IMS. |
| 4947 | return; |
| 4948 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4949 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | } finally { |
| 4951 | Binder.restoreCallingIdentity(identity); |
| 4952 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | /** |
| 4956 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4957 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4958 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4959 | */ |
| 4960 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4961 | IImsServiceFeatureCallback callback) { |
| 4962 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4963 | |
| 4964 | final long identity = Binder.clearCallingIdentity(); |
| 4965 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4966 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4967 | // may happen if the device does not support IMS. |
| 4968 | return null; |
| 4969 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4970 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4971 | } finally { |
| 4972 | Binder.restoreCallingIdentity(identity); |
| 4973 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | /** |
| 4977 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4978 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4979 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4980 | * listener for feature updates. |
| 4981 | */ |
| 4982 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4983 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4984 | |
| 4985 | final long identity = Binder.clearCallingIdentity(); |
| 4986 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4987 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4988 | // may happen if the device does not support IMS. |
| 4989 | return null; |
| 4990 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4991 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4992 | } finally { |
| 4993 | Binder.restoreCallingIdentity(identity); |
| 4994 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4995 | } |
| 4996 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4997 | /** |
| 4998 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4999 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5000 | */ |
| 5001 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5002 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | |
| 5004 | final long identity = Binder.clearCallingIdentity(); |
| 5005 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5006 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5007 | // may happen if the device does not support IMS. |
| 5008 | return null; |
| 5009 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5010 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5011 | } finally { |
| 5012 | Binder.restoreCallingIdentity(identity); |
| 5013 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5014 | } |
| 5015 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5016 | /** |
| 5017 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5018 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5019 | */ |
| 5020 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5021 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | |
| 5023 | final long identity = Binder.clearCallingIdentity(); |
| 5024 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5025 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5026 | // may happen if the device does not support IMS. |
| 5027 | return null; |
| 5028 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5029 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5030 | } finally { |
| 5031 | Binder.restoreCallingIdentity(identity); |
| 5032 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5033 | } |
| 5034 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5035 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5036 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5037 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5038 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5039 | * @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] | 5040 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5041 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5042 | * @param packageName The name of the package that the current configuration will be replaced |
| 5043 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5044 | * @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] | 5045 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5046 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5047 | int[] featureTypes, String packageName) { |
| 5048 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5049 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5050 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5051 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5052 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5053 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5056 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5057 | // may happen if the device does not support IMS. |
| 5058 | return false; |
| 5059 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5060 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5061 | for (int featureType : featureTypes) { |
| 5062 | featureConfig.put(featureType, packageName); |
| 5063 | } |
| 5064 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5065 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5066 | } finally { |
| 5067 | Binder.restoreCallingIdentity(identity); |
| 5068 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5072 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5073 | * |
| 5074 | * @param slotId The slot that the ImsService is associated with. |
| 5075 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5076 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5077 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5078 | * @return the package name of the ImsService configuration. |
| 5079 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5080 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5081 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5082 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5083 | TelephonyPermissions |
| 5084 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5085 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5086 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5087 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5088 | final long identity = Binder.clearCallingIdentity(); |
| 5089 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5090 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5091 | // may happen if the device does not support IMS. |
| 5092 | return ""; |
| 5093 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5094 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5095 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5096 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5097 | } finally { |
| 5098 | Binder.restoreCallingIdentity(identity); |
| 5099 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5102 | /** |
| 5103 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5104 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5105 | * @param callback A callback with an integer containing the |
| 5106 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5107 | */ |
| 5108 | @Override |
| 5109 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5110 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5111 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5112 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5113 | "IMS not available on device."); |
| 5114 | } |
| 5115 | final long token = Binder.clearCallingIdentity(); |
| 5116 | try { |
| 5117 | int slotId = getSlotIndex(subId); |
| 5118 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5119 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5120 | + subId + "'"); |
| 5121 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5122 | } |
| 5123 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5124 | try { |
| 5125 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5126 | } catch (RemoteException e) { |
| 5127 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5128 | + "Ignore"); |
| 5129 | } |
| 5130 | }); |
| 5131 | } finally { |
| 5132 | Binder.restoreCallingIdentity(token); |
| 5133 | } |
| 5134 | } |
| 5135 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5136 | public void setImsRegistrationState(boolean registered) { |
| 5137 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | |
| 5139 | final long identity = Binder.clearCallingIdentity(); |
| 5140 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5141 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5142 | } finally { |
| 5143 | Binder.restoreCallingIdentity(identity); |
| 5144 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5145 | } |
| 5146 | |
| 5147 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5148 | * Set the network selection mode to automatic. |
| 5149 | * |
| 5150 | */ |
| 5151 | @Override |
| 5152 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5154 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | |
| 5156 | final long identity = Binder.clearCallingIdentity(); |
| 5157 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5158 | if (!isActiveSubscription(subId)) { |
| 5159 | return; |
| 5160 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5161 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5162 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5163 | } finally { |
| 5164 | Binder.restoreCallingIdentity(identity); |
| 5165 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5168 | /** |
| 5169 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5170 | * |
| 5171 | * @param subId the id of the subscription. |
| 5172 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5173 | * the operator to attach to. |
| 5174 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5175 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5176 | * normal network selection next time. |
| 5177 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5178 | */ |
| 5179 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5180 | public boolean setNetworkSelectionModeManual( |
| 5181 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5182 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5183 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5184 | |
| 5185 | if (!isActiveSubscription(subId)) { |
| 5186 | return false; |
| 5187 | } |
| 5188 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5189 | final long identity = Binder.clearCallingIdentity(); |
| 5190 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5191 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5193 | if (DBG) { |
| 5194 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5195 | + " operator: " + operatorInfo); |
| 5196 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5197 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5198 | } finally { |
| 5199 | Binder.restoreCallingIdentity(identity); |
| 5200 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5201 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5202 | /** |
| 5203 | * Get the manual network selection |
| 5204 | * |
| 5205 | * @param subId the id of the subscription. |
| 5206 | * |
| 5207 | * @return the previously saved user selected PLMN |
| 5208 | */ |
| 5209 | @Override |
| 5210 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5211 | TelephonyPermissions |
| 5212 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5213 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5214 | |
| 5215 | final long identity = Binder.clearCallingIdentity(); |
| 5216 | try { |
| 5217 | if (!isActiveSubscription(subId)) { |
| 5218 | return ""; |
| 5219 | } |
| 5220 | |
| 5221 | final Phone phone = getPhone(subId); |
| 5222 | if (phone == null) { |
| 5223 | return ""; |
| 5224 | } |
| 5225 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5226 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5227 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
| 5230 | } |
| 5231 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5232 | |
| 5233 | /** |
| 5234 | * Scans for available networks. |
| 5235 | */ |
| 5236 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5237 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5238 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5240 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5241 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5242 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5243 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5244 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5245 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5246 | .setCallingPid(Binder.getCallingPid()) |
| 5247 | .setCallingUid(Binder.getCallingUid()) |
| 5248 | .setMethod("getCellNetworkScanResults") |
| 5249 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5250 | .build()); |
| 5251 | switch (locationResult) { |
| 5252 | case DENIED_HARD: |
| 5253 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5254 | case DENIED_SOFT: |
| 5255 | return null; |
| 5256 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5258 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5259 | try { |
| 5260 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5261 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | } finally { |
| 5264 | Binder.restoreCallingIdentity(identity); |
| 5265 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5269 | * Get the call forwarding info, given the call forwarding reason. |
| 5270 | */ |
| 5271 | @Override |
| 5272 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5273 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5274 | long identity = Binder.clearCallingIdentity(); |
| 5275 | try { |
| 5276 | if (DBG) { |
| 5277 | log("getCallForwarding: subId " + subId |
| 5278 | + " callForwardingReason" + callForwardingReason); |
| 5279 | } |
| 5280 | return (CallForwardingInfo) sendRequest( |
| 5281 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5282 | } finally { |
| 5283 | Binder.restoreCallingIdentity(identity); |
| 5284 | } |
| 5285 | } |
| 5286 | |
| 5287 | /** |
| 5288 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5289 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5290 | */ |
| 5291 | @Override |
| 5292 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5293 | enforceModifyPermission(); |
| 5294 | long identity = Binder.clearCallingIdentity(); |
| 5295 | try { |
| 5296 | if (DBG) { |
| 5297 | log("setCallForwarding: subId " + subId |
| 5298 | + " callForwardingInfo" + callForwardingInfo); |
| 5299 | } |
| 5300 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
| 5303 | } |
| 5304 | } |
| 5305 | |
| 5306 | /** |
| 5307 | * Get the call forwarding info, given the call forwarding reason. |
| 5308 | */ |
| 5309 | @Override |
| 5310 | public int getCallWaitingStatus(int subId) { |
| 5311 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5312 | long identity = Binder.clearCallingIdentity(); |
| 5313 | try { |
| 5314 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5315 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5316 | } finally { |
| 5317 | Binder.restoreCallingIdentity(identity); |
| 5318 | } |
| 5319 | } |
| 5320 | |
| 5321 | /** |
| 5322 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5323 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5324 | */ |
| 5325 | @Override |
| 5326 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5327 | enforceModifyPermission(); |
| 5328 | long identity = Binder.clearCallingIdentity(); |
| 5329 | try { |
| 5330 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5331 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5332 | } finally { |
| 5333 | Binder.restoreCallingIdentity(identity); |
| 5334 | } |
| 5335 | } |
| 5336 | |
| 5337 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5338 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5339 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5340 | * @param subId id of the subscription |
| 5341 | * @param request contains the radio access networks with bands/channels to scan |
| 5342 | * @param messenger callback messenger for scan results or errors |
| 5343 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5344 | * @return the id of the requested scan which can be used to stop the scan. |
| 5345 | */ |
| 5346 | @Override |
| 5347 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5348 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5349 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5350 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5351 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5352 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5353 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5354 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5355 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5356 | .setCallingPid(Binder.getCallingPid()) |
| 5357 | .setCallingUid(Binder.getCallingUid()) |
| 5358 | .setMethod("requestNetworkScan") |
| 5359 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5360 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5361 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5362 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5363 | if (e != null) { |
| 5364 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5365 | throw e; |
| 5366 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5367 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5368 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5369 | } |
| 5370 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5372 | int callingUid = Binder.getCallingUid(); |
| 5373 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5374 | final long identity = Binder.clearCallingIdentity(); |
| 5375 | try { |
| 5376 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5377 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5378 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5379 | } finally { |
| 5380 | Binder.restoreCallingIdentity(identity); |
| 5381 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5382 | } |
| 5383 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5384 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5385 | NetworkScanRequest request, int subId) { |
| 5386 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5387 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5388 | boolean hasNetworkScanPermission = |
| 5389 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5390 | == PERMISSION_GRANTED; |
| 5391 | |
| 5392 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5393 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5394 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5398 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5399 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5400 | return new SecurityException("Specific channels must not be" |
| 5401 | + " scanned without location access."); |
| 5402 | } |
| 5403 | } |
| 5404 | } |
| 5405 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5406 | return null; |
| 5407 | } |
| 5408 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5409 | /** |
| 5410 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5411 | * |
| 5412 | * @param subId id of the subscription |
| 5413 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5414 | */ |
| 5415 | @Override |
| 5416 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5417 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5418 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5419 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5420 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5421 | final long identity = Binder.clearCallingIdentity(); |
| 5422 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5423 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5424 | } finally { |
| 5425 | Binder.restoreCallingIdentity(identity); |
| 5426 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5430 | * Get the calculated preferred network type. |
| 5431 | * Used for debugging incorrect network type. |
| 5432 | * |
| 5433 | * @return the preferred network type, defined in RILConstants.java. |
| 5434 | */ |
| 5435 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5436 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5437 | final Phone defaultPhone = getDefaultPhone(); |
| 5438 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5439 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5440 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5441 | } |
| 5442 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5443 | final long identity = Binder.clearCallingIdentity(); |
| 5444 | try { |
| 5445 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5446 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | } finally { |
| 5448 | Binder.restoreCallingIdentity(identity); |
| 5449 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5450 | } |
| 5451 | |
| 5452 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5453 | * Get the preferred network type. |
| 5454 | * Used for device configuration by some CDMA operators. |
| 5455 | * |
| 5456 | * @return the preferred network type, defined in RILConstants.java. |
| 5457 | */ |
| 5458 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5459 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5460 | TelephonyPermissions |
| 5461 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5462 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5463 | |
| 5464 | final long identity = Binder.clearCallingIdentity(); |
| 5465 | try { |
| 5466 | if (DBG) log("getPreferredNetworkType"); |
| 5467 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5468 | int networkType = (result != null ? result[0] : -1); |
| 5469 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5470 | return networkType; |
| 5471 | } finally { |
| 5472 | Binder.restoreCallingIdentity(identity); |
| 5473 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | /** |
| 5477 | * Set the preferred network type. |
| 5478 | * Used for device configuration by some CDMA operators. |
| 5479 | * |
| 5480 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5481 | * @return true on success; false on any failure. |
| 5482 | */ |
| 5483 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5484 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5485 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5486 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | |
| 5488 | final long identity = Binder.clearCallingIdentity(); |
| 5489 | try { |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5490 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5491 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5492 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5493 | } finally { |
| 5494 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5495 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5496 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5497 | |
| 5498 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5499 | * Get the allowed network types that store in the telephony provider. |
| 5500 | * |
| 5501 | * @param subId the id of the subscription. |
| 5502 | * @return allowedNetworkTypes the allowed network types. |
| 5503 | */ |
| 5504 | @Override |
| 5505 | public long getAllowedNetworkTypes(int subId) { |
| 5506 | TelephonyPermissions |
| 5507 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5508 | mApp, subId, "getAllowedNetworkTypes"); |
| 5509 | |
| 5510 | final long identity = Binder.clearCallingIdentity(); |
| 5511 | try { |
| 5512 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5513 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5514 | } finally { |
| 5515 | Binder.restoreCallingIdentity(identity); |
| 5516 | } |
| 5517 | } |
| 5518 | |
| 5519 | /** |
| 5520 | * Set the allowed network types. |
| 5521 | * |
| 5522 | * @param subId the id of the subscription. |
| 5523 | * @param allowedNetworkTypes the allowed network types. |
| 5524 | * @return true on success; false on any failure. |
| 5525 | */ |
| 5526 | @Override |
| 5527 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5529 | mApp, subId, "setAllowedNetworkTypes"); |
| 5530 | final long identity = Binder.clearCallingIdentity(); |
| 5531 | try { |
| 5532 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5533 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5534 | String.valueOf(allowedNetworkTypes)); |
| 5535 | return setPreferredNetworkTypesInternal(subId); |
| 5536 | } finally { |
| 5537 | Binder.restoreCallingIdentity(identity); |
| 5538 | } |
| 5539 | } |
| 5540 | |
| 5541 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5542 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5543 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5544 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5545 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5546 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5547 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5548 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5549 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5550 | |
| 5551 | if (DBG) { |
| 5552 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5553 | + " networkTypes " + networkTypeBitMask |
| 5554 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5555 | + " networkMode " + networkMode); |
| 5556 | } |
| 5557 | |
| 5558 | Boolean success = (Boolean) sendRequest( |
| 5559 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5560 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5561 | return success; |
| 5562 | } |
| 5563 | |
| 5564 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5565 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5566 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5567 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5568 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5569 | * @hide |
| 5570 | */ |
| 5571 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5572 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5573 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5575 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5576 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5577 | if (phone != null) { |
| 5578 | return phone.hasMatchedTetherApnSetting(); |
| 5579 | } else { |
| 5580 | return false; |
| 5581 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | } finally { |
| 5583 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5584 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5585 | } |
| 5586 | |
| 5587 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5588 | * Set mobile data enabled |
| 5589 | * Used by the user through settings etc to turn on/off mobile data |
| 5590 | * |
| 5591 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5592 | */ |
| 5593 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5594 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5596 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5597 | |
| 5598 | final long identity = Binder.clearCallingIdentity(); |
| 5599 | try { |
| 5600 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5601 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5602 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5603 | if (phone != null) { |
| 5604 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5605 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5607 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5608 | } |
| 5609 | } finally { |
| 5610 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5611 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5615 | * Enable or disable always reporting signal strength changes from radio. |
| 5616 | * |
| 5617 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5618 | */ |
| 5619 | @Override |
| 5620 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5621 | enforceModifyPermission(); |
| 5622 | enforceSystemCaller(); |
| 5623 | |
| 5624 | final long identity = Binder.clearCallingIdentity(); |
| 5625 | final Phone phone = getPhone(subId); |
| 5626 | try { |
| 5627 | if (phone != null) { |
| 5628 | if (DBG) { |
| 5629 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5630 | + " isEnable=" + isEnable); |
| 5631 | } |
| 5632 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5633 | } else { |
| 5634 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5635 | + subId); |
| 5636 | } |
| 5637 | } finally { |
| 5638 | Binder.restoreCallingIdentity(identity); |
| 5639 | } |
| 5640 | } |
| 5641 | |
| 5642 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5643 | * Get the user enabled state of Mobile Data. |
| 5644 | * |
| 5645 | * TODO: remove and use isUserDataEnabled. |
| 5646 | * This can't be removed now because some vendor codes |
| 5647 | * calls through ITelephony directly while they should |
| 5648 | * use TelephonyManager. |
| 5649 | * |
| 5650 | * @return true on enabled |
| 5651 | */ |
| 5652 | @Override |
| 5653 | public boolean getDataEnabled(int subId) { |
| 5654 | return isUserDataEnabled(subId); |
| 5655 | } |
| 5656 | |
| 5657 | /** |
| 5658 | * Get whether mobile data is enabled per user setting. |
| 5659 | * |
| 5660 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5661 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5662 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5663 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5664 | * |
| 5665 | * @return {@code true} if data is enabled else {@code false} |
| 5666 | */ |
| 5667 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5668 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5669 | try { |
| 5670 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5671 | null); |
| 5672 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5673 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5674 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5675 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | |
| 5677 | final long identity = Binder.clearCallingIdentity(); |
| 5678 | try { |
| 5679 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5680 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5681 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5682 | if (phone != null) { |
| 5683 | boolean retVal = phone.isUserDataEnabled(); |
| 5684 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5685 | return retVal; |
| 5686 | } else { |
| 5687 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5688 | return false; |
| 5689 | } |
| 5690 | } finally { |
| 5691 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5692 | } |
| 5693 | } |
| 5694 | |
| 5695 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5696 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5697 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5698 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5699 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5700 | * @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] | 5701 | */ |
| 5702 | @Override |
| 5703 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5704 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | |
| 5706 | final long identity = Binder.clearCallingIdentity(); |
| 5707 | try { |
| 5708 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5709 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5710 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5711 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5712 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5713 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5714 | return retVal; |
| 5715 | } else { |
| 5716 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5717 | return false; |
| 5718 | } |
| 5719 | } finally { |
| 5720 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5721 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5722 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5723 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5724 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5725 | Phone phone) { |
| 5726 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5727 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5728 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5729 | || subController == null) return privilegeFromSim; |
| 5730 | |
| 5731 | int uid = Binder.getCallingUid(); |
| 5732 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5733 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5734 | |
| 5735 | final long identity = Binder.clearCallingIdentity(); |
| 5736 | try { |
| 5737 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5738 | SubscriptionManager subManager = (SubscriptionManager) |
| 5739 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5740 | for (String pkg : packages) { |
| 5741 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5742 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5743 | } |
| 5744 | } |
| 5745 | return privilegeFromSim; |
| 5746 | } finally { |
| 5747 | Binder.restoreCallingIdentity(identity); |
| 5748 | } |
| 5749 | } |
| 5750 | |
| 5751 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5752 | String pkgName) { |
| 5753 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5754 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5755 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5756 | || subController == null) return privilegeFromSim; |
| 5757 | |
| 5758 | final long identity = Binder.clearCallingIdentity(); |
| 5759 | try { |
| 5760 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5761 | SubscriptionManager subManager = (SubscriptionManager) |
| 5762 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5763 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5764 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5765 | } finally { |
| 5766 | Binder.restoreCallingIdentity(identity); |
| 5767 | } |
| 5768 | } |
| 5769 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5770 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5771 | public int getCarrierPrivilegeStatus(int subId) { |
| 5772 | final Phone phone = getPhone(subId); |
| 5773 | if (phone == null) { |
| 5774 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5775 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5776 | } |
| 5777 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5778 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5779 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5780 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5781 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5782 | |
| 5783 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5784 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5785 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5786 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5787 | |
| 5788 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5789 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5790 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5791 | final Phone phone = getPhone(subId); |
| 5792 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5793 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5794 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5795 | } |
| 5796 | UiccProfile profile = |
| 5797 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5798 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5799 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5800 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5801 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5802 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5803 | profile.getCarrierPrivilegeStatusForUid( |
| 5804 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5808 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5809 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5810 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5814 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5815 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5816 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5817 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5818 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5819 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5820 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5821 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | @Override |
| 5825 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5826 | if (TextUtils.isEmpty(pkgName)) |
| 5827 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5828 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5829 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5830 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5831 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5832 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5833 | continue; |
| 5834 | } |
| 5835 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5836 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5837 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5838 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5839 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5840 | break; |
| 5841 | } |
| 5842 | } |
| 5843 | |
| 5844 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5845 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5846 | |
| 5847 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5848 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5849 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5850 | loge("phoneId " + phoneId + " is not valid."); |
| 5851 | return null; |
| 5852 | } |
| 5853 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5854 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5855 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5856 | return null ; |
| 5857 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5858 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5859 | } |
| 5860 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5861 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5862 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5863 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5864 | List<String> privilegedPackages = new ArrayList<>(); |
| 5865 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5866 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5867 | // has UICC in that slot. |
| 5868 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5869 | if (card.hasCarrierPrivilegeRules()) { |
| 5870 | if (packages == null) { |
| 5871 | // Only check packages in user 0 for now |
| 5872 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5873 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5874 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5875 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5876 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5877 | } |
| 5878 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5879 | PackageInfo pkgInfo = packages.get(p); |
| 5880 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5881 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5882 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5883 | privilegedPackages.add(pkgInfo.packageName); |
| 5884 | } |
| 5885 | } |
| 5886 | } |
| 5887 | } |
| 5888 | return privilegedPackages; |
| 5889 | } |
| 5890 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5891 | @Override |
| 5892 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5893 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5894 | |
| 5895 | final long identity = Binder.clearCallingIdentity(); |
| 5896 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5897 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5898 | try { |
| 5899 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5900 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5901 | } |
| 5902 | } finally { |
| 5903 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5904 | } |
| 5905 | return privilegedPackages; |
| 5906 | } |
| 5907 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5908 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5909 | final Phone phone = getPhone(subId); |
| 5910 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5911 | if (card == null) { |
| 5912 | loge("getIccId: No UICC"); |
| 5913 | return null; |
| 5914 | } |
| 5915 | String iccId = card.getIccId(); |
| 5916 | if (TextUtils.isEmpty(iccId)) { |
| 5917 | loge("getIccId: ICC ID is null or empty."); |
| 5918 | return null; |
| 5919 | } |
| 5920 | return iccId; |
| 5921 | } |
| 5922 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5923 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5924 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5925 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5926 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5927 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5928 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | final long identity = Binder.clearCallingIdentity(); |
| 5930 | try { |
| 5931 | final String iccId = getIccId(subId); |
| 5932 | final Phone phone = getPhone(subId); |
| 5933 | if (phone == null) { |
| 5934 | return false; |
| 5935 | } |
| 5936 | final String subscriberId = phone.getSubscriberId(); |
| 5937 | |
| 5938 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5939 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5940 | + subscriberId + " to " + number); |
| 5941 | } |
| 5942 | |
| 5943 | if (TextUtils.isEmpty(iccId)) { |
| 5944 | return false; |
| 5945 | } |
| 5946 | |
| 5947 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5948 | |
| 5949 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5950 | if (alphaTag == null) { |
| 5951 | editor.remove(alphaTagPrefKey); |
| 5952 | } else { |
| 5953 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5954 | } |
| 5955 | |
| 5956 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5957 | // track all merged IMSIs based on line number |
| 5958 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5959 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5960 | if (number == null) { |
| 5961 | editor.remove(numberPrefKey); |
| 5962 | editor.remove(subscriberPrefKey); |
| 5963 | } else { |
| 5964 | editor.putString(numberPrefKey, number); |
| 5965 | editor.putString(subscriberPrefKey, subscriberId); |
| 5966 | } |
| 5967 | |
| 5968 | editor.commit(); |
| 5969 | return true; |
| 5970 | } finally { |
| 5971 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5972 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5973 | } |
| 5974 | |
| 5975 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5976 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5977 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5978 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5979 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5980 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5981 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5982 | return null; |
| 5983 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5984 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5985 | final long identity = Binder.clearCallingIdentity(); |
| 5986 | try { |
| 5987 | String iccId = getIccId(subId); |
| 5988 | if (iccId != null) { |
| 5989 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5990 | if (DBG_MERGE) { |
| 5991 | log("getLine1NumberForDisplay returning " |
| 5992 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5993 | } |
| 5994 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5996 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5997 | return null; |
| 5998 | } finally { |
| 5999 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6000 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6004 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6005 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6006 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6007 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6008 | return null; |
| 6009 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6010 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6011 | final long identity = Binder.clearCallingIdentity(); |
| 6012 | try { |
| 6013 | String iccId = getIccId(subId); |
| 6014 | if (iccId != null) { |
| 6015 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6016 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6017 | } |
| 6018 | return null; |
| 6019 | } finally { |
| 6020 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6021 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6022 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6023 | |
| 6024 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6025 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6026 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6027 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6028 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6029 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6030 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6031 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6032 | return null; |
| 6033 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6034 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6035 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6036 | // the process, where TelephonyManager was instantiated. |
| 6037 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6038 | final long identity = Binder.clearCallingIdentity(); |
| 6039 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6040 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6042 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6043 | |
| 6044 | // Figure out what subscribers are currently active |
| 6045 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6047 | // Only consider subs which match the current subId |
| 6048 | // This logic can be simplified. See b/131189269 for progress. |
| 6049 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6050 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6051 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6052 | |
| 6053 | // First pass, find a number override for an active subscriber |
| 6054 | String mergeNumber = null; |
| 6055 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6056 | for (String key : prefs.keySet()) { |
| 6057 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6058 | final String subscriberId = (String) prefs.get(key); |
| 6059 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6060 | final String iccId = key.substring( |
| 6061 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6062 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6063 | mergeNumber = (String) prefs.get(numberKey); |
| 6064 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6065 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6066 | + " for active subscriber " + subscriberId); |
| 6067 | } |
| 6068 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6069 | break; |
| 6070 | } |
| 6071 | } |
| 6072 | } |
| 6073 | } |
| 6074 | |
| 6075 | // Shortcut when no active merged subscribers |
| 6076 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6077 | return null; |
| 6078 | } |
| 6079 | |
| 6080 | // Second pass, find all subscribers under that line override |
| 6081 | final ArraySet<String> result = new ArraySet<>(); |
| 6082 | for (String key : prefs.keySet()) { |
| 6083 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6084 | final String number = (String) prefs.get(key); |
| 6085 | if (mergeNumber.equals(number)) { |
| 6086 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6087 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6088 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6089 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6090 | result.add(subscriberId); |
| 6091 | } |
| 6092 | } |
| 6093 | } |
| 6094 | } |
| 6095 | |
| 6096 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6097 | Arrays.sort(resultArray); |
| 6098 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6099 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6100 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6101 | } |
| 6102 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6103 | } finally { |
| 6104 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6105 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6109 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6110 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6111 | |
| 6112 | final long identity = Binder.clearCallingIdentity(); |
| 6113 | try { |
| 6114 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6115 | TelephonyManager.class); |
| 6116 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6117 | if (subscriberId == null) { |
| 6118 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6119 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6120 | + subId); |
| 6121 | } |
| 6122 | return null; |
| 6123 | } |
| 6124 | |
| 6125 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6126 | .getSubscriptionInfo(subId); |
| 6127 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6128 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6129 | if (groupUuid == null) { |
| 6130 | return new String[]{subscriberId}; |
| 6131 | } |
| 6132 | |
| 6133 | // Get all subscriberIds from the group. |
| 6134 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6135 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6136 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6137 | mApp.getFeatureId()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6138 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6139 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6140 | if (subscriberId != null) { |
| 6141 | mergedSubscriberIds.add(subscriberId); |
| 6142 | } |
| 6143 | } |
| 6144 | |
| 6145 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6146 | } finally { |
| 6147 | Binder.restoreCallingIdentity(identity); |
| 6148 | |
| 6149 | } |
| 6150 | } |
| 6151 | |
| 6152 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6153 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6154 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6155 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6156 | |
| 6157 | final long identity = Binder.clearCallingIdentity(); |
| 6158 | try { |
| 6159 | final Phone phone = getPhone(subId); |
| 6160 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6161 | } finally { |
| 6162 | Binder.restoreCallingIdentity(identity); |
| 6163 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6164 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6165 | |
| 6166 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6167 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6168 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6169 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6170 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6171 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | |
| 6173 | final long identity = Binder.clearCallingIdentity(); |
| 6174 | try { |
| 6175 | final Phone phone = getPhone(subId); |
| 6176 | if (phone == null) { |
| 6177 | return false; |
| 6178 | } |
| 6179 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6180 | cdmaNonRoamingList); |
| 6181 | } finally { |
| 6182 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6183 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6187 | @Deprecated |
| 6188 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6189 | enforceModifyPermission(); |
| 6190 | |
| 6191 | int returnValue = 0; |
| 6192 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6193 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6194 | if(result.exception == null) { |
| 6195 | if (result.result != null) { |
| 6196 | byte[] responseData = (byte[])(result.result); |
| 6197 | if(responseData.length > oemResp.length) { |
| 6198 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6199 | responseData.length + "bytes. Buffer Size is " + |
| 6200 | oemResp.length + "bytes."); |
| 6201 | } |
| 6202 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6203 | returnValue = responseData.length; |
| 6204 | } |
| 6205 | } else { |
| 6206 | CommandException ex = (CommandException) result.exception; |
| 6207 | returnValue = ex.getCommandError().ordinal(); |
| 6208 | if(returnValue > 0) returnValue *= -1; |
| 6209 | } |
| 6210 | } catch (RuntimeException e) { |
| 6211 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6212 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6213 | if(returnValue > 0) returnValue *= -1; |
| 6214 | } |
| 6215 | |
| 6216 | return returnValue; |
| 6217 | } |
| 6218 | |
| 6219 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6220 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6221 | try { |
| 6222 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6223 | } catch (RuntimeException e) { |
| 6224 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6229 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6230 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6231 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6232 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6233 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6234 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6235 | final long identity = Binder.clearCallingIdentity(); |
| 6236 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6237 | TelephonyPermissions |
| 6238 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6239 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6240 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | } finally { |
| 6242 | Binder.restoreCallingIdentity(identity); |
| 6243 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6244 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6245 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6246 | |
| 6247 | @Override |
| 6248 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6249 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6250 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6251 | |
| 6252 | final long identity = Binder.clearCallingIdentity(); |
| 6253 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6254 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6255 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6256 | } finally { |
| 6257 | Binder.restoreCallingIdentity(identity); |
| 6258 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6259 | } |
| 6260 | |
| 6261 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6262 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6263 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6264 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6265 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6266 | return false; |
| 6267 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6268 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6269 | final long identity = Binder.clearCallingIdentity(); |
| 6270 | try { |
| 6271 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6272 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6273 | // In the long run, we may instead need to check if there exists a connection service |
| 6274 | // which can support video calling. |
| 6275 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6276 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6277 | return imsManager.isVtEnabledByPlatform() |
| 6278 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6279 | && imsManager.isVtEnabledByUser(); |
| 6280 | } finally { |
| 6281 | Binder.restoreCallingIdentity(identity); |
| 6282 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6283 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6284 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6285 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6286 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6287 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6288 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6289 | mApp, subId, callingPackage, callingFeatureId, |
| 6290 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6291 | return false; |
| 6292 | } |
| 6293 | |
| 6294 | final long identity = Binder.clearCallingIdentity(); |
| 6295 | try { |
| 6296 | CarrierConfigManager configManager = |
| 6297 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6298 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6300 | } finally { |
| 6301 | Binder.restoreCallingIdentity(identity); |
| 6302 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6303 | } |
| 6304 | |
| 6305 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6306 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6307 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6308 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6309 | return false; |
| 6310 | } |
| 6311 | |
| 6312 | final long identity = Binder.clearCallingIdentity(); |
| 6313 | try { |
| 6314 | CarrierConfigManager configManager = |
| 6315 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6316 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6317 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6318 | } finally { |
| 6319 | Binder.restoreCallingIdentity(identity); |
| 6320 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6321 | } |
| 6322 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6323 | @Override |
| 6324 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6325 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6326 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6327 | } |
| 6328 | |
| 6329 | @Override |
| 6330 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6331 | final long identity = Binder.clearCallingIdentity(); |
| 6332 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6333 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | } finally { |
| 6335 | Binder.restoreCallingIdentity(identity); |
| 6336 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6337 | } |
| 6338 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6339 | /** |
| 6340 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6341 | * support for the feature and device firmware support. |
| 6342 | * |
| 6343 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6344 | */ |
| 6345 | @Override |
| 6346 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6347 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6348 | final Phone phone = getPhone(subscriptionId); |
| 6349 | if (phone == null) { |
| 6350 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6351 | return false; |
| 6352 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6354 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6355 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6356 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6357 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6358 | return isCarrierSupported && isDeviceSupported; |
| 6359 | } finally { |
| 6360 | Binder.restoreCallingIdentity(identity); |
| 6361 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6362 | } |
| 6363 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6364 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6365 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6366 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6367 | * 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] | 6368 | */ |
| 6369 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6370 | final long identity = Binder.clearCallingIdentity(); |
| 6371 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6372 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6373 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6374 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6375 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6376 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6377 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6378 | } finally { |
| 6379 | Binder.restoreCallingIdentity(identity); |
| 6380 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6381 | } |
| 6382 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6383 | @Deprecated |
| 6384 | @Override |
| 6385 | public String getDeviceId(String callingPackage) { |
| 6386 | return getDeviceIdWithFeature(callingPackage, null); |
| 6387 | } |
| 6388 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6389 | /** |
| 6390 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6391 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6392 | * |
| 6393 | * <p>Requires Permission: |
| 6394 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6395 | */ |
| 6396 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6397 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6398 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6399 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6400 | return null; |
| 6401 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6402 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6403 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6404 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6405 | return null; |
| 6406 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6407 | |
| 6408 | final long identity = Binder.clearCallingIdentity(); |
| 6409 | try { |
| 6410 | return phone.getDeviceId(); |
| 6411 | } finally { |
| 6412 | Binder.restoreCallingIdentity(identity); |
| 6413 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6414 | } |
| 6415 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6416 | /** |
| 6417 | * {@hide} |
| 6418 | * Returns the IMS Registration Status on a particular subid |
| 6419 | * |
| 6420 | * @param subId |
| 6421 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6422 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6423 | Phone phone = getPhone(subId); |
| 6424 | if (phone != null) { |
| 6425 | return phone.isImsRegistered(); |
| 6426 | } else { |
| 6427 | return false; |
| 6428 | } |
| 6429 | } |
| 6430 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6431 | @Override |
| 6432 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6433 | final long identity = Binder.clearCallingIdentity(); |
| 6434 | try { |
| 6435 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6436 | } finally { |
| 6437 | Binder.restoreCallingIdentity(identity); |
| 6438 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6439 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6440 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6441 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6442 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6443 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6444 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6445 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6446 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6447 | } |
| 6448 | final long identity = Binder.clearCallingIdentity(); |
| 6449 | try { |
| 6450 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6451 | } finally { |
| 6452 | Binder.restoreCallingIdentity(identity); |
| 6453 | } |
| 6454 | } |
| 6455 | |
| 6456 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6457 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6458 | final long identity = Binder.clearCallingIdentity(); |
| 6459 | try { |
| 6460 | Phone phone = getPhone(subscriptionId); |
| 6461 | if (phone == null) { |
| 6462 | return null; |
| 6463 | } |
| 6464 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6465 | } finally { |
| 6466 | Binder.restoreCallingIdentity(identity); |
| 6467 | } |
| 6468 | } |
| 6469 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6470 | /** |
| 6471 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6472 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6473 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6474 | final long identity = Binder.clearCallingIdentity(); |
| 6475 | try { |
| 6476 | Phone phone = getPhone(subId); |
| 6477 | if (phone != null) { |
| 6478 | return phone.isWifiCallingEnabled(); |
| 6479 | } else { |
| 6480 | return false; |
| 6481 | } |
| 6482 | } finally { |
| 6483 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6484 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6485 | } |
| 6486 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6487 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6488 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6489 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6490 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6491 | final long identity = Binder.clearCallingIdentity(); |
| 6492 | try { |
| 6493 | Phone phone = getPhone(subId); |
| 6494 | if (phone != null) { |
| 6495 | return phone.isVideoEnabled(); |
| 6496 | } else { |
| 6497 | return false; |
| 6498 | } |
| 6499 | } finally { |
| 6500 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6501 | } |
| 6502 | } |
| 6503 | |
| 6504 | /** |
| 6505 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6506 | * defined in {@link ImsRegistrationImplBase}. |
| 6507 | */ |
| 6508 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6509 | final long identity = Binder.clearCallingIdentity(); |
| 6510 | try { |
| 6511 | Phone phone = getPhone(subId); |
| 6512 | if (phone != null) { |
| 6513 | return phone.getImsRegistrationTech(); |
| 6514 | } else { |
| 6515 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6516 | } |
| 6517 | } finally { |
| 6518 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6519 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6520 | } |
| 6521 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6522 | @Override |
| 6523 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6524 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6525 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6526 | return; |
| 6527 | } |
| 6528 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6529 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6530 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6531 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6532 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6533 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6534 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6535 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6536 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6537 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6538 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6539 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6540 | // There has been issues when Sms raw table somehow stores orphan |
| 6541 | // fragments. They lead to garbled message when new fragments come |
| 6542 | // in and combined with those stale ones. In case this happens again, |
| 6543 | // user can reset all network settings which will clean up this table. |
| 6544 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6545 | // Clean up IMS settings as well here. |
| 6546 | int slotId = getSlotIndex(subId); |
| 6547 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6548 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6549 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6550 | |
| 6551 | // Erase modem config if erase modem on network setting is enabled. |
| 6552 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6553 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6554 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6555 | sendEraseModemConfig(getDefaultPhone()); |
| 6556 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6557 | } finally { |
| 6558 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6559 | } |
| 6560 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6561 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6562 | private void cleanUpSmsRawTable(Context context) { |
| 6563 | ContentResolver resolver = context.getContentResolver(); |
| 6564 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6565 | resolver.delete(uri, null, null); |
| 6566 | } |
| 6567 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6568 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6569 | public String getSimLocaleForSubscriber(int subId) { |
| 6570 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6571 | final Phone phone = getPhone(subId); |
| 6572 | if (phone == null) { |
| 6573 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6574 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6575 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6576 | final long identity = Binder.clearCallingIdentity(); |
| 6577 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6578 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6579 | phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6580 | if (info == null) { |
| 6581 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6582 | return null; |
| 6583 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6584 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6585 | // preferences (EF-PL and EF-LI)... |
| 6586 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6587 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6588 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6589 | if (localeFromDefaultSim != null) { |
| 6590 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6591 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6592 | + localeFromDefaultSim); |
| 6593 | return localeFromDefaultSim.toLanguageTag(); |
| 6594 | } else { |
| 6595 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6596 | } |
| 6597 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6598 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6599 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6600 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6601 | // the SIM and carrier preferences does not include a country we add the country |
| 6602 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6603 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6604 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6605 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6606 | return mccLocale.toLanguageTag(); |
| 6607 | } |
| 6608 | |
| 6609 | if (DBG) log("No locale found - returning null"); |
| 6610 | return null; |
| 6611 | } finally { |
| 6612 | Binder.restoreCallingIdentity(identity); |
| 6613 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6614 | } |
| 6615 | |
| 6616 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6617 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6618 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6619 | } |
| 6620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6621 | /** |
| 6622 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6623 | */ |
| 6624 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6625 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6626 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6627 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6628 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6629 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6630 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6631 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6632 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6633 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6634 | * representing the state of the modem. |
| 6635 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6636 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6637 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6638 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6639 | */ |
| 6640 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6641 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6642 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6643 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6644 | |
| 6645 | final long identity = Binder.clearCallingIdentity(); |
| 6646 | try { |
| 6647 | ModemActivityInfo ret = null; |
| 6648 | synchronized (mLastModemActivityInfo) { |
| 6649 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6650 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6651 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6652 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6653 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6654 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6655 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6656 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6657 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6658 | } |
| 6659 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6660 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6661 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6662 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6663 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6664 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6665 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6666 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6667 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6668 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6669 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6670 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6671 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6672 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6673 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6674 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6675 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6676 | Bundle bundle = new Bundle(); |
| 6677 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6678 | result.send(0, bundle); |
| 6679 | } finally { |
| 6680 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6681 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6682 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6683 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6684 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6685 | // less than total activity duration. |
| 6686 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6687 | if (info == null) { |
| 6688 | return false; |
| 6689 | } |
| 6690 | int activityDurationMs = |
| 6691 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6692 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6693 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6694 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6695 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6696 | } |
| 6697 | return (info.isValid() |
| 6698 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6699 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6700 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6701 | && (totalTxTimeMs <= activityDurationMs)); |
| 6702 | } |
| 6703 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6704 | /** |
| 6705 | * {@hide} |
| 6706 | * Returns the service state information on specified subscription. |
| 6707 | */ |
| 6708 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6709 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6710 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6711 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6712 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6713 | return null; |
| 6714 | } |
| 6715 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6716 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6717 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6718 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6719 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6720 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6721 | .setCallingPid(Binder.getCallingPid()) |
| 6722 | .setCallingUid(Binder.getCallingUid()) |
| 6723 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6724 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6725 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6726 | .build()); |
| 6727 | |
| 6728 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6729 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6730 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6731 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6732 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6733 | .setCallingPid(Binder.getCallingPid()) |
| 6734 | .setCallingUid(Binder.getCallingUid()) |
| 6735 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6736 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6737 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6738 | .build()); |
| 6739 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6740 | boolean hasFinePermission = |
| 6741 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6742 | boolean hasCoarsePermission = |
| 6743 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6744 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6745 | final long identity = Binder.clearCallingIdentity(); |
| 6746 | try { |
| 6747 | final Phone phone = getPhone(subId); |
| 6748 | if (phone == null) { |
| 6749 | return null; |
| 6750 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6751 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6752 | ServiceState ss = phone.getServiceState(); |
| 6753 | |
| 6754 | // Scrub out the location info in ServiceState depending on what level of access |
| 6755 | // the caller has. |
| 6756 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6757 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6758 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | } finally { |
| 6760 | Binder.restoreCallingIdentity(identity); |
| 6761 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6762 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6763 | |
| 6764 | /** |
| 6765 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6766 | * |
| 6767 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6768 | * voicemail ringtone. |
| 6769 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6770 | * PhoneAccount. |
| 6771 | */ |
| 6772 | @Override |
| 6773 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6774 | final long identity = Binder.clearCallingIdentity(); |
| 6775 | try { |
| 6776 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6777 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6778 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6779 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6780 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6781 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6782 | } finally { |
| 6783 | Binder.restoreCallingIdentity(identity); |
| 6784 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6788 | * Sets the per-account voicemail ringtone. |
| 6789 | * |
| 6790 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6791 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6792 | * |
| 6793 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6794 | * voicemail ringtone. |
| 6795 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6796 | * PhoneAccount. |
| 6797 | */ |
| 6798 | @Override |
| 6799 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6800 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6801 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6802 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6803 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6804 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6805 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6806 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6807 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6808 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6809 | |
| 6810 | final long identity = Binder.clearCallingIdentity(); |
| 6811 | try { |
| 6812 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6813 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6814 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6815 | } |
| 6816 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6817 | } finally { |
| 6818 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6819 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6820 | } |
| 6821 | |
| 6822 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6823 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6824 | * |
| 6825 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6826 | * voicemail vibration setting. |
| 6827 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6828 | */ |
| 6829 | @Override |
| 6830 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | final long identity = Binder.clearCallingIdentity(); |
| 6832 | try { |
| 6833 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6834 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6835 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6836 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6837 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6838 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6839 | } finally { |
| 6840 | Binder.restoreCallingIdentity(identity); |
| 6841 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6842 | } |
| 6843 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6844 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6845 | * Sets the per-account voicemail vibration. |
| 6846 | * |
| 6847 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6848 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6849 | * |
| 6850 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6851 | * voicemail vibration setting. |
| 6852 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6853 | * specific PhoneAccount. |
| 6854 | */ |
| 6855 | @Override |
| 6856 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6857 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6858 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6859 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6860 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6861 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6863 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6864 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6865 | } |
| 6866 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6867 | final long identity = Binder.clearCallingIdentity(); |
| 6868 | try { |
| 6869 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6870 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6871 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6872 | } |
| 6873 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6874 | } finally { |
| 6875 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6876 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6877 | } |
| 6878 | |
| 6879 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6880 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6881 | * |
| 6882 | * @throws SecurityException if the caller does not have the required permission |
| 6883 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6884 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6885 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6886 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6887 | } |
| 6888 | |
| 6889 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6890 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6891 | * permission. |
| 6892 | * |
| 6893 | * @throws SecurityException if the caller does not have the required permission |
| 6894 | */ |
| 6895 | private void enforceSendSmsPermission() { |
| 6896 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6897 | } |
| 6898 | |
| 6899 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6900 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6901 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6902 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6903 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6904 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6905 | final long identity = Binder.clearCallingIdentity(); |
| 6906 | try { |
| 6907 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6908 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6909 | if (componentName == null) { |
| 6910 | throw new SecurityException( |
| 6911 | "Caller not current active visual voicemail package[null]"); |
| 6912 | } |
| 6913 | String vvmPackage = componentName.getPackageName(); |
| 6914 | if (!callingPackage.equals(vvmPackage)) { |
| 6915 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6916 | + vvmPackage + "]"); |
| 6917 | } |
| 6918 | } finally { |
| 6919 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6920 | } |
| 6921 | } |
| 6922 | |
| 6923 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6924 | * Return the application ID for the app type. |
| 6925 | * |
| 6926 | * @param subId the subscription ID that this request applies to. |
| 6927 | * @param appType the uicc app type. |
| 6928 | * @return Application ID for specificied app type, or null if no uicc. |
| 6929 | */ |
| 6930 | @Override |
| 6931 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6932 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6933 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6934 | |
| 6935 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6936 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6937 | if (phone == null) { |
| 6938 | return null; |
| 6939 | } |
| 6940 | String aid = null; |
| 6941 | try { |
| 6942 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6943 | .getApplicationByType(appType).getAid(); |
| 6944 | } catch (Exception e) { |
| 6945 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6946 | } |
| 6947 | return aid; |
| 6948 | } finally { |
| 6949 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6950 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6951 | } |
| 6952 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6953 | /** |
| 6954 | * Return the Electronic Serial Number. |
| 6955 | * |
| 6956 | * @param subId the subscription ID that this request applies to. |
| 6957 | * @return ESN or null if error. |
| 6958 | */ |
| 6959 | @Override |
| 6960 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6961 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6962 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6963 | |
| 6964 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6965 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6966 | if (phone == null) { |
| 6967 | return null; |
| 6968 | } |
| 6969 | String esn = null; |
| 6970 | try { |
| 6971 | esn = phone.getEsn(); |
| 6972 | } catch (Exception e) { |
| 6973 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6974 | } |
| 6975 | return esn; |
| 6976 | } finally { |
| 6977 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6978 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6979 | } |
| 6980 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6981 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6982 | * Return the Preferred Roaming List Version. |
| 6983 | * |
| 6984 | * @param subId the subscription ID that this request applies to. |
| 6985 | * @return PRLVersion or null if error. |
| 6986 | */ |
| 6987 | @Override |
| 6988 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6989 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6990 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6991 | |
| 6992 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6993 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6994 | if (phone == null) { |
| 6995 | return null; |
| 6996 | } |
| 6997 | String cdmaPrlVersion = null; |
| 6998 | try { |
| 6999 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7000 | } catch (Exception e) { |
| 7001 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7002 | } |
| 7003 | return cdmaPrlVersion; |
| 7004 | } finally { |
| 7005 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7006 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7007 | } |
| 7008 | |
| 7009 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7010 | * Get snapshot of Telephony histograms |
| 7011 | * @return List of Telephony histograms |
| 7012 | * @hide |
| 7013 | */ |
| 7014 | @Override |
| 7015 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7016 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7017 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | |
| 7019 | final long identity = Binder.clearCallingIdentity(); |
| 7020 | try { |
| 7021 | return RIL.getTelephonyRILTimingHistograms(); |
| 7022 | } finally { |
| 7023 | Binder.restoreCallingIdentity(identity); |
| 7024 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7025 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7026 | |
| 7027 | /** |
| 7028 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7029 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7030 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7031 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7032 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7033 | * @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] | 7034 | */ |
| 7035 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7036 | @TelephonyManager.SetCarrierRestrictionResult |
| 7037 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7038 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7039 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7040 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7041 | if (carrierRestrictionRules == null) { |
| 7042 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7043 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7044 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7047 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7048 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7049 | } finally { |
| 7050 | Binder.restoreCallingIdentity(identity); |
| 7051 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | /** |
| 7055 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7056 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7057 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7058 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7059 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7060 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7061 | */ |
| 7062 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7063 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7064 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7065 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7066 | |
| 7067 | final long identity = Binder.clearCallingIdentity(); |
| 7068 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7069 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7070 | if (response instanceof CarrierRestrictionRules) { |
| 7071 | return (CarrierRestrictionRules) response; |
| 7072 | } |
| 7073 | // Response is an Exception of some kind, |
| 7074 | // which is signalled to the user as a NULL retval |
| 7075 | return null; |
| 7076 | } catch (Exception e) { |
| 7077 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7078 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | } finally { |
| 7080 | Binder.restoreCallingIdentity(identity); |
| 7081 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7082 | } |
| 7083 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7084 | /** |
| 7085 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7086 | * @param subId the subscription ID that this action applies to. |
| 7087 | * @param enabled control enable or disable metered apns. |
| 7088 | * {@hide} |
| 7089 | */ |
| 7090 | @Override |
| 7091 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7092 | enforceModifyPermission(); |
| 7093 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7094 | |
| 7095 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7096 | if (phone == null) { |
| 7097 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7098 | return; |
| 7099 | } |
| 7100 | try { |
| 7101 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7102 | } catch (Exception e) { |
| 7103 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7104 | } finally { |
| 7105 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7106 | } |
| 7107 | } |
| 7108 | |
| 7109 | /** |
| 7110 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7111 | * @param subId the subscription ID that this action applies to. |
| 7112 | * @param enabled control enable or disable radio. |
| 7113 | * {@hide} |
| 7114 | */ |
| 7115 | @Override |
| 7116 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7117 | enforceModifyPermission(); |
| 7118 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7119 | |
| 7120 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7121 | if (phone == null) { |
| 7122 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7123 | return; |
| 7124 | } |
| 7125 | try { |
| 7126 | phone.carrierActionSetRadioEnabled(enabled); |
| 7127 | } catch (Exception e) { |
| 7128 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7129 | } finally { |
| 7130 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7131 | } |
| 7132 | } |
| 7133 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7134 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7135 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7136 | * network status based on which carrier apps could apply actions accordingly, |
| 7137 | * enable/disable default url handler for example. |
| 7138 | * |
| 7139 | * @param subId the subscription ID that this action applies to. |
| 7140 | * @param report control start/stop reporting the default network status. |
| 7141 | * {@hide} |
| 7142 | */ |
| 7143 | @Override |
| 7144 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7145 | enforceModifyPermission(); |
| 7146 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7147 | |
| 7148 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7149 | if (phone == null) { |
| 7150 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7151 | return; |
| 7152 | } |
| 7153 | try { |
| 7154 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7155 | } catch (Exception e) { |
| 7156 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | } finally { |
| 7158 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7159 | } |
| 7160 | } |
| 7161 | |
| 7162 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7163 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7164 | * @param subId the subscription ID that this action applies to. |
| 7165 | * {@hide} |
| 7166 | */ |
| 7167 | @Override |
| 7168 | public void carrierActionResetAll(int subId) { |
| 7169 | enforceModifyPermission(); |
| 7170 | final Phone phone = getPhone(subId); |
| 7171 | if (phone == null) { |
| 7172 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7173 | return; |
| 7174 | } |
| 7175 | try { |
| 7176 | phone.carrierActionResetAll(); |
| 7177 | } catch (Exception e) { |
| 7178 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7183 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7184 | * bug report is being generated. |
| 7185 | */ |
| 7186 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7187 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7188 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7189 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7190 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7191 | + Binder.getCallingPid() |
| 7192 | + ", uid=" + Binder.getCallingUid() |
| 7193 | + "without permission " |
| 7194 | + android.Manifest.permission.DUMP); |
| 7195 | return; |
| 7196 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7197 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7198 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7199 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7200 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7201 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7202 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7203 | @NonNull String[] args) { |
| 7204 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7205 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7206 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7207 | } |
| 7208 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7209 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7210 | * Policy control of data connection. Usually used when data limit is passed. |
| 7211 | * @param enabled True if enabling the data, otherwise disabling. |
| 7212 | * @param subId Subscription index |
| 7213 | * {@hide} |
| 7214 | */ |
| 7215 | @Override |
| 7216 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7217 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7218 | |
| 7219 | final long identity = Binder.clearCallingIdentity(); |
| 7220 | try { |
| 7221 | Phone phone = getPhone(subId); |
| 7222 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7223 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7224 | } |
| 7225 | } finally { |
| 7226 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7227 | } |
| 7228 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7229 | |
| 7230 | /** |
| 7231 | * Get Client request stats |
| 7232 | * @return List of Client Request Stats |
| 7233 | * @hide |
| 7234 | */ |
| 7235 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7236 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7237 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7239 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7240 | return null; |
| 7241 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7242 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7243 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7244 | final long identity = Binder.clearCallingIdentity(); |
| 7245 | try { |
| 7246 | if (phone != null) { |
| 7247 | return phone.getClientRequestStats(); |
| 7248 | } |
| 7249 | |
| 7250 | return null; |
| 7251 | } finally { |
| 7252 | Binder.restoreCallingIdentity(identity); |
| 7253 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7254 | } |
| 7255 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7256 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7257 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7258 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7259 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7260 | |
| 7261 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7262 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7263 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7264 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7265 | * @param state State of SIM (power down, power up, pass through) |
| 7266 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7267 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7268 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7269 | * |
| 7270 | **/ |
| 7271 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7272 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7273 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7274 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7275 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7276 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7277 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7278 | final long identity = Binder.clearCallingIdentity(); |
| 7279 | try { |
| 7280 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7281 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7282 | } |
| 7283 | } finally { |
| 7284 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7285 | } |
| 7286 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7287 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7288 | private boolean isUssdApiAllowed(int subId) { |
| 7289 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7290 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7291 | if (configManager == null) { |
| 7292 | return false; |
| 7293 | } |
| 7294 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7295 | if (pb == null) { |
| 7296 | return false; |
| 7297 | } |
| 7298 | return pb.getBoolean( |
| 7299 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7300 | } |
| 7301 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7302 | /** |
| 7303 | * Check if phone is in emergency callback mode |
| 7304 | * @return true if phone is in emergency callback mode |
| 7305 | * @param subId sub id |
| 7306 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7307 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7308 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7309 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7310 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7311 | |
| 7312 | final long identity = Binder.clearCallingIdentity(); |
| 7313 | try { |
| 7314 | if (phone != null) { |
| 7315 | return phone.isInEcm(); |
| 7316 | } else { |
| 7317 | return false; |
| 7318 | } |
| 7319 | } finally { |
| 7320 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7321 | } |
| 7322 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7323 | |
| 7324 | /** |
| 7325 | * Get the current signal strength information for the given subscription. |
| 7326 | * Because this information is not updated when the device is in a low power state |
| 7327 | * it should not be relied-upon to be current. |
| 7328 | * @param subId Subscription index |
| 7329 | * @return the most recent cached signal strength info from the modem |
| 7330 | */ |
| 7331 | @Override |
| 7332 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | final long identity = Binder.clearCallingIdentity(); |
| 7334 | try { |
| 7335 | Phone p = getPhone(subId); |
| 7336 | if (p == null) { |
| 7337 | return null; |
| 7338 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7339 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7340 | return p.getSignalStrength(); |
| 7341 | } finally { |
| 7342 | Binder.restoreCallingIdentity(identity); |
| 7343 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7344 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7345 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7346 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7347 | * Get the current modem radio state for the given slot. |
| 7348 | * @param slotIndex slot index. |
| 7349 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7350 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7351 | * @return the current radio power state from the modem |
| 7352 | */ |
| 7353 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7354 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7355 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7356 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7357 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7358 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7359 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7360 | } |
| 7361 | |
| 7362 | final long identity = Binder.clearCallingIdentity(); |
| 7363 | try { |
| 7364 | return phone.getRadioPowerState(); |
| 7365 | } finally { |
| 7366 | Binder.restoreCallingIdentity(identity); |
| 7367 | } |
| 7368 | } |
| 7369 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7370 | } |
| 7371 | |
| 7372 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7373 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7374 | * |
| 7375 | * <p>Requires one of the following permissions: |
| 7376 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7377 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7378 | * privileges. |
| 7379 | * |
| 7380 | * @param subId subscription id |
| 7381 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7382 | * {@code false}. |
| 7383 | */ |
| 7384 | @Override |
| 7385 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7386 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7387 | null /* message */); |
| 7388 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7389 | boolean isEnabled = false; |
| 7390 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7391 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7392 | Phone phone = getPhone(subId); |
| 7393 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7394 | } catch (Exception e) { |
| 7395 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7396 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7397 | } finally { |
| 7398 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7399 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7400 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7401 | } |
| 7402 | |
| 7403 | |
| 7404 | /** |
| 7405 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7406 | * |
| 7407 | * <p> Requires permission: |
| 7408 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7409 | * privileges. |
| 7410 | * |
| 7411 | * @param subId subscription id |
| 7412 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7413 | */ |
| 7414 | @Override |
| 7415 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7417 | mApp, subId, "setDataRoamingEnabled"); |
| 7418 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7419 | final long identity = Binder.clearCallingIdentity(); |
| 7420 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7421 | Phone phone = getPhone(subId); |
| 7422 | if (phone != null) { |
| 7423 | phone.setDataRoamingEnabled(isEnabled); |
| 7424 | } |
| 7425 | } finally { |
| 7426 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7427 | } |
| 7428 | } |
| 7429 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7430 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7431 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7432 | TelephonyPermissions |
| 7433 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7434 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7435 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7436 | boolean isAllowed = true; |
| 7437 | final long identity = Binder.clearCallingIdentity(); |
| 7438 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7439 | Phone phone = getPhone(subId); |
| 7440 | if (phone != null) { |
| 7441 | isAllowed = phone.isCspPlmnEnabled(); |
| 7442 | } |
| 7443 | } finally { |
| 7444 | Binder.restoreCallingIdentity(identity); |
| 7445 | } |
| 7446 | return isAllowed; |
| 7447 | } |
| 7448 | |
| 7449 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7450 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 102b277 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 7451 | try { |
| 7452 | PackageManager pm = mApp.getPackageManager(); |
| 7453 | if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) { |
| 7454 | throw new SecurityException("Calling package " + callingPackage + " does not match " |
| 7455 | + "calling UID"); |
| 7456 | } |
| 7457 | } catch (PackageManager.NameNotFoundException e) { |
| 7458 | throw new SecurityException("Invalid calling package. e=" + e); |
| 7459 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7460 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7461 | try { |
| 7462 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7463 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7464 | } catch (SecurityException e) { |
| 7465 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7466 | // has carrier privileges on an active UICC |
| 7467 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7468 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7469 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7470 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7471 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7472 | |
| 7473 | final long identity = Binder.clearCallingIdentity(); |
| 7474 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7475 | UiccController uiccController = UiccController.getInstance(); |
| 7476 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7477 | if (hasReadPermission) { |
| 7478 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7479 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7480 | |
| 7481 | // Remove private info if the caller doesn't have access |
| 7482 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7483 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7484 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7485 | // is available |
| 7486 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7487 | if (card == null || card.getUiccProfile() == null) { |
| 7488 | // assume no access if the card or profile is unavailable |
| 7489 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7490 | continue; |
| 7491 | } |
| 7492 | UiccProfile profile = card.getUiccProfile(); |
| 7493 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7494 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7495 | filteredInfos.add(cardInfo); |
| 7496 | } else { |
| 7497 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7498 | } |
| 7499 | } |
| 7500 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7501 | } finally { |
| 7502 | Binder.restoreCallingIdentity(identity); |
| 7503 | } |
| 7504 | } |
| 7505 | |
| 7506 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7507 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7508 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7509 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7510 | final long identity = Binder.clearCallingIdentity(); |
| 7511 | try { |
| 7512 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7513 | if (slots == null) { |
| 7514 | Rlog.i(LOG_TAG, "slots is null."); |
| 7515 | return null; |
| 7516 | } |
| 7517 | |
| 7518 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7519 | for (int i = 0; i < slots.length; i++) { |
| 7520 | UiccSlot slot = slots[i]; |
| 7521 | if (slot == null) { |
| 7522 | continue; |
| 7523 | } |
| 7524 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7525 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | UiccCard card = slot.getUiccCard(); |
| 7527 | if (card != null) { |
| 7528 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7529 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7530 | cardId = slot.getEid(); |
| 7531 | if (TextUtils.isEmpty(cardId)) { |
| 7532 | cardId = slot.getIccId(); |
| 7533 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7534 | } |
| 7535 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7536 | if (cardId != null) { |
| 7537 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7538 | // if cardId is an EID, it's all digits so this is fine |
| 7539 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7540 | } |
| 7541 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | int cardState = 0; |
| 7543 | switch (slot.getCardState()) { |
| 7544 | case CARDSTATE_ABSENT: |
| 7545 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7546 | break; |
| 7547 | case CARDSTATE_PRESENT: |
| 7548 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7549 | break; |
| 7550 | case CARDSTATE_ERROR: |
| 7551 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7552 | break; |
| 7553 | case CARDSTATE_RESTRICTED: |
| 7554 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7555 | break; |
| 7556 | default: |
| 7557 | break; |
| 7558 | |
| 7559 | } |
| 7560 | |
| 7561 | infos[i] = new UiccSlotInfo( |
| 7562 | slot.isActive(), |
| 7563 | slot.isEuicc(), |
| 7564 | cardId, |
| 7565 | cardState, |
| 7566 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7567 | slot.isExtendedApduSupported(), |
| 7568 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7569 | } |
| 7570 | return infos; |
| 7571 | } finally { |
| 7572 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7573 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7574 | } |
| 7575 | |
| 7576 | @Override |
| 7577 | public boolean switchSlots(int[] physicalSlots) { |
| 7578 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7579 | |
| 7580 | final long identity = Binder.clearCallingIdentity(); |
| 7581 | try { |
| 7582 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7583 | } finally { |
| 7584 | Binder.restoreCallingIdentity(identity); |
| 7585 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7586 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7587 | |
| 7588 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7589 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7590 | final long identity = Binder.clearCallingIdentity(); |
| 7591 | try { |
| 7592 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7593 | } finally { |
| 7594 | Binder.restoreCallingIdentity(identity); |
| 7595 | } |
| 7596 | } |
| 7597 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7598 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7599 | * A test API to reload the UICC profile. |
| 7600 | * |
| 7601 | * <p>Requires that the calling app has permission |
| 7602 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7603 | * @hide |
| 7604 | */ |
| 7605 | @Override |
| 7606 | public void refreshUiccProfile(int subId) { |
| 7607 | enforceModifyPermission(); |
| 7608 | |
| 7609 | final long identity = Binder.clearCallingIdentity(); |
| 7610 | try { |
| 7611 | Phone phone = getPhone(subId); |
| 7612 | if (phone == null) { |
| 7613 | return; |
| 7614 | } |
| 7615 | UiccCard uiccCard = phone.getUiccCard(); |
| 7616 | if (uiccCard == null) { |
| 7617 | return; |
| 7618 | } |
| 7619 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7620 | if (uiccProfile == null) { |
| 7621 | return; |
| 7622 | } |
| 7623 | uiccProfile.refresh(); |
| 7624 | } finally { |
| 7625 | Binder.restoreCallingIdentity(identity); |
| 7626 | } |
| 7627 | } |
| 7628 | |
| 7629 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7630 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7631 | */ |
| 7632 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7633 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7634 | } |
| 7635 | |
| 7636 | /** |
| 7637 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7638 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7639 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7640 | */ |
| 7641 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7642 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7643 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7644 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7645 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7646 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7647 | return isDataRoamingEnabled; |
| 7648 | } |
| 7649 | |
| 7650 | /** |
| 7651 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7652 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7653 | */ |
| 7654 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7655 | List<Integer> list = TelephonyProperties.default_network(); |
| 7656 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7657 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7658 | return list.get(phoneId); |
| 7659 | } |
| 7660 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7661 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7662 | |
| 7663 | @Override |
| 7664 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7665 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7666 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7667 | |
| 7668 | final long identity = Binder.clearCallingIdentity(); |
| 7669 | try { |
| 7670 | final Phone phone = getPhone(subId); |
| 7671 | if (phone == null) { |
| 7672 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7673 | return; |
| 7674 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7675 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7676 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7677 | } finally { |
| 7678 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7679 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7680 | } |
| 7681 | |
| 7682 | @Override |
| 7683 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7684 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7685 | |
| 7686 | final long identity = Binder.clearCallingIdentity(); |
| 7687 | try { |
| 7688 | final Phone phone = getPhone(subId); |
| 7689 | if (phone == null) { |
| 7690 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7691 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7692 | } |
| 7693 | return phone.getCarrierIdListVersion(); |
| 7694 | } finally { |
| 7695 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7696 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7697 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7698 | |
| 7699 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7700 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7701 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7702 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7703 | mApp, subId, callingPackage, callingFeatureId, |
| 7704 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7705 | return -1; |
| 7706 | } |
| 7707 | |
| 7708 | final long identity = Binder.clearCallingIdentity(); |
| 7709 | try { |
| 7710 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7711 | } finally { |
| 7712 | Binder.restoreCallingIdentity(identity); |
| 7713 | } |
| 7714 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7715 | |
| 7716 | @Override |
| 7717 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7718 | TelephonyPermissions |
| 7719 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7720 | mApp, subId, "getCdmaRoamingMode"); |
| 7721 | |
| 7722 | final long identity = Binder.clearCallingIdentity(); |
| 7723 | try { |
| 7724 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7725 | } finally { |
| 7726 | Binder.restoreCallingIdentity(identity); |
| 7727 | } |
| 7728 | } |
| 7729 | |
| 7730 | @Override |
| 7731 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7732 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7733 | mApp, subId, "setCdmaRoamingMode"); |
| 7734 | |
| 7735 | final long identity = Binder.clearCallingIdentity(); |
| 7736 | try { |
| 7737 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7738 | } finally { |
| 7739 | Binder.restoreCallingIdentity(identity); |
| 7740 | } |
| 7741 | } |
| 7742 | |
| 7743 | @Override |
| 7744 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7745 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7746 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7747 | |
| 7748 | final long identity = Binder.clearCallingIdentity(); |
| 7749 | try { |
| 7750 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7751 | } finally { |
| 7752 | Binder.restoreCallingIdentity(identity); |
| 7753 | } |
| 7754 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7755 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7756 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7757 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7758 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7759 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7760 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7761 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7762 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7763 | } |
| 7764 | final long identity = Binder.clearCallingIdentity(); |
| 7765 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7766 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7767 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7768 | if (phone.getEmergencyNumberTracker() != null |
| 7769 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7770 | emergencyNumberListInternal.put( |
| 7771 | phone.getSubId(), |
| 7772 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7773 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7774 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7775 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7776 | } finally { |
| 7777 | Binder.restoreCallingIdentity(identity); |
| 7778 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7779 | } |
| 7780 | |
| 7781 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7782 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7783 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7784 | if (!exactMatch) { |
| 7785 | TelephonyPermissions |
| 7786 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7787 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7788 | } |
| 7789 | final long identity = Binder.clearCallingIdentity(); |
| 7790 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7791 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7792 | if (phone.getEmergencyNumberTracker() != null |
| 7793 | && phone.getEmergencyNumberTracker() != null) { |
| 7794 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7795 | number, exactMatch)) { |
| 7796 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7797 | } |
| 7798 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7799 | } |
| 7800 | return false; |
| 7801 | } finally { |
| 7802 | Binder.restoreCallingIdentity(identity); |
| 7803 | } |
| 7804 | } |
| 7805 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7806 | /** |
| 7807 | * Update emergency number list for test mode. |
| 7808 | */ |
| 7809 | @Override |
| 7810 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7811 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7812 | "updateEmergencyNumberListTestMode"); |
| 7813 | |
| 7814 | final long identity = Binder.clearCallingIdentity(); |
| 7815 | try { |
| 7816 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7817 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7818 | if (tracker != null) { |
| 7819 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7820 | } |
| 7821 | } |
| 7822 | } finally { |
| 7823 | Binder.restoreCallingIdentity(identity); |
| 7824 | } |
| 7825 | } |
| 7826 | |
| 7827 | /** |
| 7828 | * Get the full emergency number list for test mode. |
| 7829 | */ |
| 7830 | @Override |
| 7831 | public List<String> getEmergencyNumberListTestMode() { |
| 7832 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7833 | "getEmergencyNumberListTestMode"); |
| 7834 | |
| 7835 | final long identity = Binder.clearCallingIdentity(); |
| 7836 | try { |
| 7837 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7838 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7839 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7840 | if (tracker != null) { |
| 7841 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7842 | emergencyNumbers.add(num.getNumber()); |
| 7843 | } |
| 7844 | } |
| 7845 | } |
| 7846 | return new ArrayList<>(emergencyNumbers); |
| 7847 | } finally { |
| 7848 | Binder.restoreCallingIdentity(identity); |
| 7849 | } |
| 7850 | } |
| 7851 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7852 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7853 | public int getEmergencyNumberDbVersion(int subId) { |
| 7854 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7855 | |
| 7856 | final long identity = Binder.clearCallingIdentity(); |
| 7857 | try { |
| 7858 | final Phone phone = getPhone(subId); |
| 7859 | if (phone == null) { |
| 7860 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7861 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7862 | } |
| 7863 | return phone.getEmergencyNumberDbVersion(); |
| 7864 | } finally { |
| 7865 | Binder.restoreCallingIdentity(identity); |
| 7866 | } |
| 7867 | } |
| 7868 | |
| 7869 | @Override |
| 7870 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7871 | enforceModifyPermission(); |
| 7872 | |
| 7873 | final long identity = Binder.clearCallingIdentity(); |
| 7874 | try { |
| 7875 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7876 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7877 | if (tracker != null) { |
| 7878 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7879 | } |
| 7880 | } |
| 7881 | } finally { |
| 7882 | Binder.restoreCallingIdentity(identity); |
| 7883 | } |
| 7884 | } |
| 7885 | |
| 7886 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame^] | 7887 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7888 | enforceActiveEmergencySessionPermission(); |
| 7889 | |
| 7890 | final long identity = Binder.clearCallingIdentity(); |
| 7891 | try { |
| 7892 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7893 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7894 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame^] | 7895 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 7896 | } |
| 7897 | } |
| 7898 | } finally { |
| 7899 | Binder.restoreCallingIdentity(identity); |
| 7900 | } |
| 7901 | } |
| 7902 | |
| 7903 | @Override |
| 7904 | public void resetOtaEmergencyNumberDbFilePath() { |
| 7905 | enforceActiveEmergencySessionPermission(); |
| 7906 | |
| 7907 | final long identity = Binder.clearCallingIdentity(); |
| 7908 | try { |
| 7909 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7910 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7911 | if (tracker != null) { |
| 7912 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7913 | } |
| 7914 | } |
| 7915 | } finally { |
| 7916 | Binder.restoreCallingIdentity(identity); |
| 7917 | } |
| 7918 | } |
| 7919 | |
| 7920 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7921 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7922 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7923 | Phone phone = getPhone(subId); |
| 7924 | if (phone == null) { |
| 7925 | return null; |
| 7926 | } |
| 7927 | final long identity = Binder.clearCallingIdentity(); |
| 7928 | try { |
| 7929 | UiccProfile profile = UiccController.getInstance() |
| 7930 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7931 | if (profile != null) { |
| 7932 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7933 | } |
| 7934 | } finally { |
| 7935 | Binder.restoreCallingIdentity(identity); |
| 7936 | } |
| 7937 | return null; |
| 7938 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7939 | |
| 7940 | /** |
| 7941 | * Enable or disable a modem stack. |
| 7942 | */ |
| 7943 | @Override |
| 7944 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7945 | enforceModifyPermission(); |
| 7946 | |
| 7947 | final long identity = Binder.clearCallingIdentity(); |
| 7948 | try { |
| 7949 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7950 | if (phone == null) { |
| 7951 | return false; |
| 7952 | } else { |
| 7953 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7954 | } |
| 7955 | } finally { |
| 7956 | Binder.restoreCallingIdentity(identity); |
| 7957 | } |
| 7958 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7959 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7960 | /** |
| 7961 | * Whether a modem stack is enabled or not. |
| 7962 | */ |
| 7963 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7964 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7965 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7966 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7967 | if (phone == null) return false; |
| 7968 | |
| 7969 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7970 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7971 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7972 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7973 | } |
| 7974 | |
| 7975 | final long identity = Binder.clearCallingIdentity(); |
| 7976 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7977 | try { |
| 7978 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7979 | } catch (NoSuchElementException ex) { |
| 7980 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7981 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7982 | } finally { |
| 7983 | Binder.restoreCallingIdentity(identity); |
| 7984 | } |
| 7985 | } |
| 7986 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7987 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7988 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7989 | enforceModifyPermission(); |
| 7990 | |
| 7991 | final long identity = Binder.clearCallingIdentity(); |
| 7992 | try { |
| 7993 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7994 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7995 | .commit(); |
| 7996 | } finally { |
| 7997 | Binder.restoreCallingIdentity(identity); |
| 7998 | } |
| 7999 | } |
| 8000 | |
| 8001 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8002 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8003 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8004 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8005 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8006 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8007 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8008 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8009 | |
| 8010 | final long identity = Binder.clearCallingIdentity(); |
| 8011 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8012 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8013 | } finally { |
| 8014 | Binder.restoreCallingIdentity(identity); |
| 8015 | } |
| 8016 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8017 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8018 | @TelephonyManager.IsMultiSimSupportedResult |
| 8019 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8020 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8021 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8022 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8023 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8024 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8025 | } |
| 8026 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8027 | // supported by the modem, indicate that it is restricted. |
| 8028 | PhoneCapability staticCapability = |
| 8029 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8030 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8031 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8032 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8033 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8034 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8035 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8036 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8037 | } |
| 8038 | // Check if support of multiple SIMs is restricted by carrier |
| 8039 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8040 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8041 | } |
| 8042 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8043 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8044 | } |
| 8045 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8046 | /** |
| 8047 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8048 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8049 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8050 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8051 | * @param numOfSims number of active sims we want to switch to |
| 8052 | */ |
| 8053 | @Override |
| 8054 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8055 | if (numOfSims == 1) { |
| 8056 | enforceModifyPermission(); |
| 8057 | } else { |
| 8058 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8059 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8060 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8061 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8062 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8063 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8064 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8065 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8066 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8067 | return; |
| 8068 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8069 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8070 | } finally { |
| 8071 | Binder.restoreCallingIdentity(identity); |
| 8072 | } |
| 8073 | } |
| 8074 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8075 | @Override |
| 8076 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8077 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8078 | Phone phone = getPhone(subId); |
| 8079 | if (phone == null) { |
| 8080 | return false; |
| 8081 | } |
| 8082 | final long identity = Binder.clearCallingIdentity(); |
| 8083 | try { |
| 8084 | UiccCard uiccCard = phone.getUiccCard(); |
| 8085 | if (uiccCard == null) { |
| 8086 | return false; |
| 8087 | } |
| 8088 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8089 | if (uiccProfile == null) { |
| 8090 | return false; |
| 8091 | } |
| 8092 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8093 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8094 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8095 | } |
| 8096 | return false; |
| 8097 | } finally { |
| 8098 | Binder.restoreCallingIdentity(identity); |
| 8099 | } |
| 8100 | } |
| 8101 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8102 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8103 | * Get whether making changes to modem configurations will trigger reboot. |
| 8104 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8105 | */ |
| 8106 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8107 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8108 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8109 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8110 | mApp, subId, callingPackage, callingFeatureId, |
| 8111 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8112 | return false; |
| 8113 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8114 | final long identity = Binder.clearCallingIdentity(); |
| 8115 | try { |
| 8116 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8117 | } finally { |
| 8118 | Binder.restoreCallingIdentity(identity); |
| 8119 | } |
| 8120 | } |
| 8121 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8122 | private void updateModemStateMetrics() { |
| 8123 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8124 | // TODO: check the state for each modem if the api is ready. |
| 8125 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8126 | } |
| 8127 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8128 | @Override |
| 8129 | public int[] getSlotsMapping() { |
| 8130 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8131 | |
| 8132 | final long identity = Binder.clearCallingIdentity(); |
| 8133 | try { |
| 8134 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8135 | // All logical slots should have a mapping to a physical slot. |
| 8136 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8137 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8138 | for (int i = 0; i < slotInfos.length; i++) { |
| 8139 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8140 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8141 | } |
| 8142 | } |
| 8143 | return logicalSlotsMapping; |
| 8144 | } finally { |
| 8145 | Binder.restoreCallingIdentity(identity); |
| 8146 | } |
| 8147 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8148 | |
| 8149 | /** |
| 8150 | * Get the IRadio HAL Version |
| 8151 | */ |
| 8152 | @Override |
| 8153 | public int getRadioHalVersion() { |
| 8154 | Phone phone = getDefaultPhone(); |
| 8155 | if (phone == null) return -1; |
| 8156 | HalVersion hv = phone.getHalVersion(); |
| 8157 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8158 | return hv.major * 100 + hv.minor; |
| 8159 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8160 | |
| 8161 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8162 | * Get the current calling package name. |
| 8163 | * @return the current calling package name |
| 8164 | */ |
| 8165 | @Override |
| 8166 | public String getCurrentPackageName() { |
| 8167 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8168 | } |
| 8169 | |
| 8170 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8171 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8172 | * corresponding network requests on a subId. |
| 8173 | * |
| 8174 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8175 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8176 | * 2) APN is un-metered for this subscription, or |
| 8177 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8178 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8179 | * |
| 8180 | * @return whether data is allowed for a apn type. |
| 8181 | * |
| 8182 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8183 | */ |
| 8184 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8185 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8186 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8187 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8188 | |
| 8189 | // Now that all security checks passes, perform the operation as ourselves. |
| 8190 | final long identity = Binder.clearCallingIdentity(); |
| 8191 | try { |
| 8192 | Phone phone = getPhone(subId); |
| 8193 | if (phone == null) return false; |
| 8194 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8195 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8196 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8197 | } finally { |
| 8198 | Binder.restoreCallingIdentity(identity); |
| 8199 | } |
| 8200 | } |
| 8201 | |
| 8202 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8203 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8204 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8205 | |
| 8206 | // Now that all security checks passes, perform the operation as ourselves. |
| 8207 | final long identity = Binder.clearCallingIdentity(); |
| 8208 | try { |
| 8209 | Phone phone = getPhone(subId); |
| 8210 | if (phone == null) return true; // By default return true. |
| 8211 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8212 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8213 | } finally { |
| 8214 | Binder.restoreCallingIdentity(identity); |
| 8215 | } |
| 8216 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8217 | |
| 8218 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8219 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8220 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8221 | enforceModifyPermission(); |
| 8222 | long token = Binder.clearCallingIdentity(); |
| 8223 | try { |
| 8224 | Phone phone = getPhone(subscriptionId); |
| 8225 | if (phone == null) { |
| 8226 | try { |
| 8227 | if (resultCallback != null) { |
| 8228 | resultCallback.accept(false); |
| 8229 | } |
| 8230 | } catch (RemoteException e) { |
| 8231 | // ignore |
| 8232 | } |
| 8233 | return; |
| 8234 | } |
| 8235 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8236 | Pair.create(specifiers, (x) -> { |
| 8237 | try { |
| 8238 | if (resultCallback != null) { |
| 8239 | resultCallback.accept(x); |
| 8240 | } |
| 8241 | } catch (RemoteException e) { |
| 8242 | // ignore |
| 8243 | } |
| 8244 | }); |
| 8245 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8246 | } finally { |
| 8247 | Binder.restoreCallingIdentity(token); |
| 8248 | } |
| 8249 | } |
| 8250 | |
| 8251 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8252 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8253 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8254 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8255 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8256 | if (iccRecords == null) { |
| 8257 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8258 | return false; |
| 8259 | } |
| 8260 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8261 | } |
| 8262 | |
| 8263 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8264 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8265 | if (callingPackage == null) { |
| 8266 | callingPackage = getCurrentPackageName(); |
| 8267 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8268 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8269 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8270 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8271 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8272 | } |
| 8273 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8274 | Intent intent = new Intent(); |
| 8275 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8276 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8277 | // Bring up choose default SMS subscription dialog right now |
| 8278 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8279 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8280 | mApp.startActivity(intent); |
| 8281 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8282 | |
| 8283 | @Override |
| 8284 | public String getMmsUAProfUrl(int subId) { |
| 8285 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8286 | final long identity = Binder.clearCallingIdentity(); |
| 8287 | try { |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8288 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8289 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8290 | } finally { |
| 8291 | Binder.restoreCallingIdentity(identity); |
| 8292 | } |
| 8293 | } |
| 8294 | |
| 8295 | @Override |
| 8296 | public String getMmsUserAgent(int subId) { |
| 8297 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8298 | final long identity = Binder.clearCallingIdentity(); |
| 8299 | try { |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8300 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8301 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8302 | } finally { |
| 8303 | Binder.restoreCallingIdentity(identity); |
| 8304 | } |
| 8305 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8306 | |
| 8307 | @Override |
| 8308 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8309 | enforceModifyPermission(); |
| 8310 | |
| 8311 | // Now that all security checks passes, perform the operation as ourselves. |
| 8312 | final long identity = Binder.clearCallingIdentity(); |
| 8313 | try { |
| 8314 | Phone phone = getPhone(subId); |
| 8315 | if (phone == null) return false; |
| 8316 | |
| 8317 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8318 | } finally { |
| 8319 | Binder.restoreCallingIdentity(identity); |
| 8320 | } |
| 8321 | } |
| 8322 | |
| 8323 | @Override |
| 8324 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8325 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8326 | |
| 8327 | // Now that all security checks passes, perform the operation as ourselves. |
| 8328 | final long identity = Binder.clearCallingIdentity(); |
| 8329 | try { |
| 8330 | Phone phone = getPhone(subId); |
| 8331 | if (phone == null) return false; |
| 8332 | |
| 8333 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8334 | } finally { |
| 8335 | Binder.restoreCallingIdentity(identity); |
| 8336 | } |
| 8337 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8338 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8339 | @Override |
| 8340 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8341 | enforceModifyPermission(); |
| 8342 | |
| 8343 | // Now that all security checks passes, perform the operation as ourselves. |
| 8344 | final long identity = Binder.clearCallingIdentity(); |
| 8345 | try { |
| 8346 | Phone phone = getPhone(subId); |
| 8347 | if (phone == null) return false; |
| 8348 | |
| 8349 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8350 | } finally { |
| 8351 | Binder.restoreCallingIdentity(identity); |
| 8352 | } |
| 8353 | } |
| 8354 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8355 | /** |
| 8356 | * Updates whether conference event pacakge handling is enabled. |
| 8357 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8358 | * otherwise. |
| 8359 | */ |
| 8360 | @Override |
| 8361 | public void setCepEnabled(boolean isCepEnabled) { |
| 8362 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8363 | |
| 8364 | final long identity = Binder.clearCallingIdentity(); |
| 8365 | try { |
| 8366 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8367 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8368 | Phone defaultPhone = phone.getImsPhone(); |
| 8369 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8370 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8371 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8372 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8373 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8374 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8375 | + imsPhone.getMsisdn()); |
| 8376 | } |
| 8377 | } |
| 8378 | } finally { |
| 8379 | Binder.restoreCallingIdentity(identity); |
| 8380 | } |
| 8381 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8382 | |
| 8383 | /** |
| 8384 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8385 | * |
| 8386 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8387 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8388 | * before being read. |
| 8389 | */ |
| 8390 | @Override |
| 8391 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8392 | isCompressed) { |
| 8393 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8394 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8395 | try { |
| 8396 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8397 | if (configBinder == null) { |
| 8398 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8399 | } else { |
| 8400 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8401 | } |
| 8402 | } catch (RemoteException e) { |
| 8403 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8404 | } |
| 8405 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8406 | |
| 8407 | @Override |
| 8408 | public boolean isIccLockEnabled(int subId) { |
| 8409 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8410 | |
| 8411 | // Now that all security checks passes, perform the operation as ourselves. |
| 8412 | final long identity = Binder.clearCallingIdentity(); |
| 8413 | try { |
| 8414 | Phone phone = getPhone(subId); |
| 8415 | if (phone != null && phone.getIccCard() != null) { |
| 8416 | return phone.getIccCard().getIccLockEnabled(); |
| 8417 | } else { |
| 8418 | return false; |
| 8419 | } |
| 8420 | } finally { |
| 8421 | Binder.restoreCallingIdentity(identity); |
| 8422 | } |
| 8423 | } |
| 8424 | |
| 8425 | /** |
| 8426 | * Set the ICC pin lock enabled or disabled. |
| 8427 | * |
| 8428 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8429 | * three cases: |
| 8430 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8431 | * successfully. |
| 8432 | * - Positive number and zero for remaining password attempts. |
| 8433 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8434 | * |
| 8435 | */ |
| 8436 | @Override |
| 8437 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8438 | enforceModifyPermission(); |
| 8439 | |
| 8440 | Phone phone = getPhone(subId); |
| 8441 | if (phone == null) { |
| 8442 | return 0; |
| 8443 | } |
| 8444 | // Now that all security checks passes, perform the operation as ourselves. |
| 8445 | final long identity = Binder.clearCallingIdentity(); |
| 8446 | try { |
| 8447 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8448 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8449 | return attemptsRemaining; |
| 8450 | |
| 8451 | } catch (Exception e) { |
| 8452 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8453 | } finally { |
| 8454 | Binder.restoreCallingIdentity(identity); |
| 8455 | } |
| 8456 | return 0; |
| 8457 | } |
| 8458 | |
| 8459 | /** |
| 8460 | * Change the ICC password used in ICC pin lock. |
| 8461 | * |
| 8462 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8463 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8464 | * - Positive number and zero for remaining password attempts. |
| 8465 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8466 | * |
| 8467 | */ |
| 8468 | @Override |
| 8469 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8470 | enforceModifyPermission(); |
| 8471 | |
| 8472 | Phone phone = getPhone(subId); |
| 8473 | if (phone == null) { |
| 8474 | return 0; |
| 8475 | } |
| 8476 | // Now that all security checks passes, perform the operation as ourselves. |
| 8477 | final long identity = Binder.clearCallingIdentity(); |
| 8478 | try { |
| 8479 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8480 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8481 | return attemptsRemaining; |
| 8482 | |
| 8483 | } catch (Exception e) { |
| 8484 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8485 | } finally { |
| 8486 | Binder.restoreCallingIdentity(identity); |
| 8487 | } |
| 8488 | return 0; |
| 8489 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8490 | |
| 8491 | /** |
| 8492 | * Request for receiving user activity notification |
| 8493 | */ |
| 8494 | @Override |
| 8495 | public void requestUserActivityNotification() { |
| 8496 | if (!mNotifyUserActivity.get() |
| 8497 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8498 | mNotifyUserActivity.set(true); |
| 8499 | } |
| 8500 | } |
| 8501 | |
| 8502 | /** |
| 8503 | * Called when userActivity is signalled in the power manager. |
| 8504 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8505 | */ |
| 8506 | @Override |
| 8507 | public void userActivity() { |
| 8508 | // *************************************** |
| 8509 | // * Inherited from PhoneWindowManager * |
| 8510 | // *************************************** |
| 8511 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8512 | // WITH ITS LOCKS HELD. |
| 8513 | // |
| 8514 | // This code must be VERY careful about the locks |
| 8515 | // it acquires. |
| 8516 | // In fact, the current code acquires way too many, |
| 8517 | // and probably has lurking deadlocks. |
| 8518 | |
| 8519 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8520 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8521 | } |
| 8522 | |
| 8523 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8524 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8525 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8526 | } |
| 8527 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8528 | } |