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; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 118 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 121 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 122 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 123 | import com.android.ims.internal.IImsServiceFeatureCallback; |
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); |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1031 | } else { |
| 1032 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1033 | Bundle bundle = new Bundle(); |
| 1034 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1035 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1036 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1037 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1038 | break; |
| 1039 | |
| 1040 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1041 | ar = (AsyncResult) msg.obj; |
| 1042 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1043 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1044 | |
| 1045 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1046 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1047 | // Update the last modem activity info and the result of the request. |
| 1048 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1049 | if (isModemActivityInfoValid(info)) { |
| 1050 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1051 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1052 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1053 | .getTransmitTimeMillis(); |
| 1054 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1055 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1056 | } |
| 1057 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1058 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1059 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1060 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1061 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1062 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1063 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1064 | info.getReceiveTimeMillis() |
| 1065 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1066 | } |
| 1067 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1068 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1069 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1070 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1071 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1072 | } else { |
| 1073 | if (ar.result == null) { |
| 1074 | loge("queryModemActivityInfo: Empty response"); |
| 1075 | } else if (ar.exception instanceof CommandException) { |
| 1076 | loge("queryModemActivityInfo: CommandException: " + |
| 1077 | ar.exception); |
| 1078 | } else { |
| 1079 | loge("queryModemActivityInfo: Unknown exception"); |
| 1080 | } |
| 1081 | } |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1082 | Bundle bundle = new Bundle(); |
| 1083 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1084 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1085 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1086 | break; |
| 1087 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1088 | case CMD_SET_ALLOWED_CARRIERS: |
| 1089 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1090 | CarrierRestrictionRules argument = |
| 1091 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1092 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1093 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1094 | break; |
| 1095 | |
| 1096 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1097 | ar = (AsyncResult) msg.obj; |
| 1098 | request = (MainThreadRequest) ar.userObj; |
| 1099 | if (ar.exception == null && ar.result != null) { |
| 1100 | request.result = ar.result; |
| 1101 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1102 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1103 | if (ar.exception instanceof CommandException) { |
| 1104 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1105 | CommandException.Error error = |
| 1106 | ((CommandException) (ar.exception)).getCommandError(); |
| 1107 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1108 | request.result = |
| 1109 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1110 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1111 | } else { |
| 1112 | loge("setAllowedCarriers: Unknown exception"); |
| 1113 | } |
| 1114 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1115 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1116 | break; |
| 1117 | |
| 1118 | case CMD_GET_ALLOWED_CARRIERS: |
| 1119 | request = (MainThreadRequest) msg.obj; |
| 1120 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1121 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1122 | break; |
| 1123 | |
| 1124 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1125 | ar = (AsyncResult) msg.obj; |
| 1126 | request = (MainThreadRequest) ar.userObj; |
| 1127 | if (ar.exception == null && ar.result != null) { |
| 1128 | request.result = ar.result; |
| 1129 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1130 | request.result = new IllegalStateException( |
| 1131 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1132 | if (ar.result == null) { |
| 1133 | loge("getAllowedCarriers: Empty response"); |
| 1134 | } else if (ar.exception instanceof CommandException) { |
| 1135 | loge("getAllowedCarriers: CommandException: " + |
| 1136 | ar.exception); |
| 1137 | } else { |
| 1138 | loge("getAllowedCarriers: Unknown exception"); |
| 1139 | } |
| 1140 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1141 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1142 | break; |
| 1143 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1144 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1145 | ar = (AsyncResult) msg.obj; |
| 1146 | request = (MainThreadRequest) ar.userObj; |
| 1147 | if (ar.exception == null && ar.result != null) { |
| 1148 | request.result = ar.result; |
| 1149 | } else { |
| 1150 | request.result = new IllegalArgumentException( |
| 1151 | "Failed to retrieve Forbidden Plmns"); |
| 1152 | if (ar.result == null) { |
| 1153 | loge("getForbiddenPlmns: Empty response"); |
| 1154 | } else { |
| 1155 | loge("getForbiddenPlmns: Unknown exception"); |
| 1156 | } |
| 1157 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1158 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1159 | break; |
| 1160 | |
| 1161 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1162 | request = (MainThreadRequest) msg.obj; |
| 1163 | uiccCard = getUiccCardFromRequest(request); |
| 1164 | if (uiccCard == null) { |
| 1165 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1166 | request.result = new IllegalArgumentException( |
| 1167 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1168 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1169 | break; |
| 1170 | } |
| 1171 | Integer appType = (Integer) request.argument; |
| 1172 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1173 | if (uiccApp == null) { |
| 1174 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1175 | + appType); |
| 1176 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1177 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1178 | break; |
| 1179 | } else { |
| 1180 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1181 | + " specified type -- " + appType); |
| 1182 | } |
| 1183 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1184 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1185 | onCompleted); |
| 1186 | break; |
| 1187 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1188 | case CMD_SWITCH_SLOTS: |
| 1189 | request = (MainThreadRequest) msg.obj; |
| 1190 | int[] physicalSlots = (int[]) request.argument; |
| 1191 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1192 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1193 | break; |
| 1194 | |
| 1195 | case EVENT_SWITCH_SLOTS_DONE: |
| 1196 | ar = (AsyncResult) msg.obj; |
| 1197 | request = (MainThreadRequest) ar.userObj; |
| 1198 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1199 | notifyRequester(request); |
| 1200 | break; |
| 1201 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1202 | request = (MainThreadRequest) msg.obj; |
| 1203 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1204 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1205 | break; |
| 1206 | |
| 1207 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1208 | ar = (AsyncResult) msg.obj; |
| 1209 | request = (MainThreadRequest) ar.userObj; |
| 1210 | if (ar.exception != null) { |
| 1211 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1212 | } else { |
| 1213 | int mode = ((int[]) ar.result)[0]; |
| 1214 | if (mode == 0) { |
| 1215 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1216 | } else { |
| 1217 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1218 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1219 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1220 | notifyRequester(request); |
| 1221 | break; |
| 1222 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1223 | request = (MainThreadRequest) msg.obj; |
| 1224 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1225 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1226 | break; |
| 1227 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1228 | ar = (AsyncResult) msg.obj; |
| 1229 | request = (MainThreadRequest) ar.userObj; |
| 1230 | if (ar.exception != null) { |
| 1231 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1232 | } else { |
| 1233 | request.result = ((int[]) ar.result)[0]; |
| 1234 | } |
| 1235 | notifyRequester(request); |
| 1236 | break; |
| 1237 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1238 | request = (MainThreadRequest) msg.obj; |
| 1239 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1240 | int mode = (int) request.argument; |
| 1241 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1242 | break; |
| 1243 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1244 | ar = (AsyncResult) msg.obj; |
| 1245 | request = (MainThreadRequest) ar.userObj; |
| 1246 | request.result = ar.exception == null; |
| 1247 | notifyRequester(request); |
| 1248 | break; |
| 1249 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1250 | request = (MainThreadRequest) msg.obj; |
| 1251 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1252 | int subscriptionMode = (int) request.argument; |
| 1253 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1254 | break; |
| 1255 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1256 | ar = (AsyncResult) msg.obj; |
| 1257 | request = (MainThreadRequest) ar.userObj; |
| 1258 | request.result = ar.exception == null; |
| 1259 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1260 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1261 | case CMD_GET_ALL_CELL_INFO: |
| 1262 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1263 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1264 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1265 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1266 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1267 | ar = (AsyncResult) msg.obj; |
| 1268 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1269 | // If a timeout occurs, the response will be null |
| 1270 | request.result = (ar.exception == null && ar.result != null) |
| 1271 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1272 | synchronized (request) { |
| 1273 | request.notifyAll(); |
| 1274 | } |
| 1275 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1276 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1277 | request = (MainThreadRequest) msg.obj; |
| 1278 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1279 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1280 | break; |
| 1281 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1282 | ar = (AsyncResult) msg.obj; |
| 1283 | request = (MainThreadRequest) ar.userObj; |
| 1284 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1285 | try { |
| 1286 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1287 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1288 | cb.onError( |
| 1289 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1290 | ar.exception.getClass().getName(), |
| 1291 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1292 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1293 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1294 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1295 | } else { |
| 1296 | // use the result as returned |
| 1297 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1298 | } |
| 1299 | } catch (RemoteException re) { |
| 1300 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1301 | } |
| 1302 | break; |
| 1303 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1304 | request = (MainThreadRequest) msg.obj; |
| 1305 | WorkSource ws = (WorkSource) request.argument; |
| 1306 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1307 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1308 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1309 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1310 | ar = (AsyncResult) msg.obj; |
| 1311 | request = (MainThreadRequest) ar.userObj; |
| 1312 | if (ar.exception == null) { |
| 1313 | request.result = ar.result; |
| 1314 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1315 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1316 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1317 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | synchronized (request) { |
| 1321 | request.notifyAll(); |
| 1322 | } |
| 1323 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1324 | case CMD_MODEM_REBOOT: |
| 1325 | request = (MainThreadRequest) msg.obj; |
| 1326 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1327 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1328 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1329 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1330 | handleNullReturnEvent(msg, "rebootModem"); |
| 1331 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1332 | case CMD_REQUEST_ENABLE_MODEM: |
| 1333 | request = (MainThreadRequest) msg.obj; |
| 1334 | boolean enable = (boolean) request.argument; |
| 1335 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1336 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1337 | PhoneConfigurationManager.getInstance() |
| 1338 | .enablePhone(request.phone, enable, onCompleted); |
| 1339 | break; |
| 1340 | case EVENT_ENABLE_MODEM_DONE: |
| 1341 | ar = (AsyncResult) msg.obj; |
| 1342 | request = (MainThreadRequest) ar.userObj; |
| 1343 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1344 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1345 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1346 | if ((boolean) request.result) { |
| 1347 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1348 | updateModemStateMetrics(); |
| 1349 | } else { |
| 1350 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1351 | + ar.exception); |
| 1352 | } |
| 1353 | notifyRequester(request); |
| 1354 | break; |
| 1355 | case CMD_GET_MODEM_STATUS: |
| 1356 | request = (MainThreadRequest) msg.obj; |
| 1357 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1358 | PhoneConfigurationManager.getInstance() |
| 1359 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1360 | break; |
| 1361 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1362 | ar = (AsyncResult) msg.obj; |
| 1363 | request = (MainThreadRequest) ar.userObj; |
| 1364 | int id = request.phone.getPhoneId(); |
| 1365 | if (ar.exception == null && ar.result != null) { |
| 1366 | request.result = ar.result; |
| 1367 | //update the cache as modem status has changed |
| 1368 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1369 | (boolean) request.result); |
| 1370 | } else { |
| 1371 | // Return true if modem status cannot be retrieved. For most cases, |
| 1372 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1373 | // and disable modem are not supported. Modem is always on. |
| 1374 | // TODO: this should be fixed in R to support a third |
| 1375 | // status UNKNOWN b/131631629 |
| 1376 | request.result = true; |
| 1377 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1378 | + ar.exception); |
| 1379 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1380 | notifyRequester(request); |
| 1381 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1382 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1383 | request = (MainThreadRequest) msg.obj; |
| 1384 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1385 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1386 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1387 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1388 | break; |
| 1389 | } |
| 1390 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1391 | ar = (AsyncResult) msg.obj; |
| 1392 | request = (MainThreadRequest) ar.userObj; |
| 1393 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1394 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1395 | args.second.accept(ar.exception == null); |
| 1396 | notifyRequester(request); |
| 1397 | break; |
| 1398 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1399 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1400 | ar = (AsyncResult) msg.obj; |
| 1401 | request = (MainThreadRequest) ar.userObj; |
| 1402 | if (ar.exception == null && ar.result != null) { |
| 1403 | request.result = ar.result; |
| 1404 | } else { |
| 1405 | request.result = -1; |
| 1406 | loge("Failed to set Forbidden Plmns"); |
| 1407 | if (ar.result == null) { |
| 1408 | loge("setForbidenPlmns: Empty response"); |
| 1409 | } else if (ar.exception != null) { |
| 1410 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1411 | request.result = -1; |
| 1412 | } else { |
| 1413 | loge("setForbiddenPlmns: Unknown exception"); |
| 1414 | } |
| 1415 | } |
| 1416 | notifyRequester(request); |
| 1417 | break; |
| 1418 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1419 | request = (MainThreadRequest) msg.obj; |
| 1420 | uiccCard = getUiccCardFromRequest(request); |
| 1421 | if (uiccCard == null) { |
| 1422 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1423 | request.result = -1; |
| 1424 | notifyRequester(request); |
| 1425 | break; |
| 1426 | } |
| 1427 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1428 | (Pair<Integer, List<String>>) request.argument; |
| 1429 | appType = setFplmnsArgs.first; |
| 1430 | List<String> fplmns = setFplmnsArgs.second; |
| 1431 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1432 | if (uiccApp == null) { |
| 1433 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1434 | request.result = -1; |
| 1435 | loge("Failed to get UICC App"); |
| 1436 | notifyRequester(request); |
| 1437 | } else { |
| 1438 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1439 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1440 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1441 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1442 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1443 | case CMD_ERASE_MODEM_CONFIG: |
| 1444 | request = (MainThreadRequest) msg.obj; |
| 1445 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1446 | defaultPhone.eraseModemConfig(onCompleted); |
| 1447 | break; |
| 1448 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1449 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1450 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1451 | |
| 1452 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1453 | request = (MainThreadRequest) msg.obj; |
| 1454 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1455 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1456 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1457 | changed.first, changed.second, onCompleted); |
| 1458 | break; |
| 1459 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1460 | ar = (AsyncResult) msg.obj; |
| 1461 | request = (MainThreadRequest) ar.userObj; |
| 1462 | if (ar.exception == null) { |
| 1463 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1464 | } else { |
| 1465 | request.result = msg.arg1; |
| 1466 | } |
| 1467 | notifyRequester(request); |
| 1468 | break; |
| 1469 | |
| 1470 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1471 | request = (MainThreadRequest) msg.obj; |
| 1472 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1473 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1474 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1475 | enabled.first, enabled.second, onCompleted); |
| 1476 | break; |
| 1477 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1478 | ar = (AsyncResult) msg.obj; |
| 1479 | request = (MainThreadRequest) ar.userObj; |
| 1480 | if (ar.exception == null) { |
| 1481 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1482 | } else { |
| 1483 | request.result = msg.arg1; |
| 1484 | } |
| 1485 | notifyRequester(request); |
| 1486 | break; |
| 1487 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1488 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1489 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1490 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1491 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1492 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1493 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1494 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1495 | default: |
| 1496 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1497 | break; |
| 1498 | } |
| 1499 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1500 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1501 | private void notifyRequester(MainThreadRequest request) { |
| 1502 | synchronized (request) { |
| 1503 | request.notifyAll(); |
| 1504 | } |
| 1505 | } |
| 1506 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1507 | private void handleNullReturnEvent(Message msg, String command) { |
| 1508 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1509 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1510 | if (ar.exception == null) { |
| 1511 | request.result = true; |
| 1512 | } else { |
| 1513 | request.result = false; |
| 1514 | if (ar.exception instanceof CommandException) { |
| 1515 | loge(command + ": CommandException: " + ar.exception); |
| 1516 | } else { |
| 1517 | loge(command + ": Unknown exception"); |
| 1518 | } |
| 1519 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1520 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1521 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | /** |
| 1525 | * Posts the specified command to be executed on the main thread, |
| 1526 | * waits for the request to complete, and returns the result. |
| 1527 | * @see #sendRequestAsync |
| 1528 | */ |
| 1529 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1530 | return sendRequest( |
| 1531 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | /** |
| 1535 | * Posts the specified command to be executed on the main thread, |
| 1536 | * waits for the request to complete, and returns the result. |
| 1537 | * @see #sendRequestAsync |
| 1538 | */ |
| 1539 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1540 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1541 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | /** |
| 1545 | * Posts the specified command to be executed on the main thread, |
| 1546 | * waits for the request to complete, and returns the result. |
| 1547 | * @see #sendRequestAsync |
| 1548 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1549 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1550 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | /** |
| 1554 | * Posts the specified command to be executed on the main thread, |
| 1555 | * waits for the request to complete, and returns the result. |
| 1556 | * @see #sendRequestAsync |
| 1557 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1558 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1559 | return sendRequest(command, argument, subId, null, workSource); |
| 1560 | } |
| 1561 | |
| 1562 | /** |
| 1563 | * Posts the specified command to be executed on the main thread, |
| 1564 | * waits for the request to complete, and returns the result. |
| 1565 | * @see #sendRequestAsync |
| 1566 | */ |
| 1567 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1568 | return sendRequest( |
| 1569 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * Posts the specified command to be executed on the main thread, |
| 1574 | * waits for the request to complete, and returns the result. |
| 1575 | * @see #sendRequestAsync |
| 1576 | */ |
| 1577 | private Object sendRequest( |
| 1578 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1579 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1580 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1581 | } |
| 1582 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1583 | MainThreadRequest request = null; |
| 1584 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1585 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1586 | } else if (phone != null) { |
| 1587 | request = new MainThreadRequest(argument, phone, workSource); |
| 1588 | } else { |
| 1589 | request = new MainThreadRequest(argument, subId, workSource); |
| 1590 | } |
| 1591 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1592 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1593 | msg.sendToTarget(); |
| 1594 | |
| 1595 | // Wait for the request to complete |
| 1596 | synchronized (request) { |
| 1597 | while (request.result == null) { |
| 1598 | try { |
| 1599 | request.wait(); |
| 1600 | } catch (InterruptedException e) { |
| 1601 | // Do nothing, go back and wait until the request is complete |
| 1602 | } |
| 1603 | } |
| 1604 | } |
| 1605 | return request.result; |
| 1606 | } |
| 1607 | |
| 1608 | /** |
| 1609 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1610 | * Posts the specified command to be executed on the main thread, and |
| 1611 | * returns immediately. |
| 1612 | * @see #sendRequest |
| 1613 | */ |
| 1614 | private void sendRequestAsync(int command) { |
| 1615 | mMainThreadHandler.sendEmptyMessage(command); |
| 1616 | } |
| 1617 | |
| 1618 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1619 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1620 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1621 | */ |
| 1622 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1623 | sendRequestAsync(command, argument, null, null); |
| 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1628 | * @see {@link #sendRequest(int,Object)} |
| 1629 | */ |
| 1630 | private void sendRequestAsync( |
| 1631 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1632 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1633 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1634 | msg.sendToTarget(); |
| 1635 | } |
| 1636 | |
| 1637 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1638 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1639 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1640 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1641 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1642 | synchronized (PhoneInterfaceManager.class) { |
| 1643 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1644 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1645 | } else { |
| 1646 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1647 | } |
| 1648 | return sInstance; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1653 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1654 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1655 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1656 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1657 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1658 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1659 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1660 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1661 | mTelephonySharedPreferences = |
| 1662 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1663 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1664 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1665 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1666 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1667 | publish(); |
| 1668 | } |
| 1669 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1670 | private Phone getDefaultPhone() { |
| 1671 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1672 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1673 | } |
| 1674 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1675 | private void publish() { |
| 1676 | if (DBG) log("publish: " + this); |
| 1677 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1678 | TelephonyFrameworkInitializer |
| 1679 | .getTelephonyServiceManager() |
| 1680 | .getTelephonyServiceRegisterer() |
| 1681 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1684 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1685 | if (request.phone != null) { |
| 1686 | return request.phone; |
| 1687 | } else { |
| 1688 | return getPhoneFromSubId(request.subId); |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | private Phone getPhoneFromSubId(int subId) { |
| 1693 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1694 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1695 | } |
| 1696 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1697 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1698 | Phone phone = getPhoneFromRequest(request); |
| 1699 | return phone == null ? null : |
| 1700 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1701 | } |
| 1702 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1703 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1704 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1705 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1706 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1707 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1708 | private void sendEraseModemConfig(Phone phone) { |
| 1709 | if (phone != null) { |
| 1710 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1711 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1712 | final long identity = Binder.clearCallingIdentity(); |
| 1713 | try { |
| 1714 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1715 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1716 | } finally { |
| 1717 | Binder.restoreCallingIdentity(identity); |
| 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1722 | private boolean isImsAvailableOnDevice() { |
| 1723 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1724 | if (pm == null) { |
| 1725 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1726 | // so do not throw error and allow. |
| 1727 | return true; |
| 1728 | } |
| 1729 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1730 | } |
| 1731 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1732 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1733 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1736 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1737 | if (DBG) log("dial: " + number); |
| 1738 | // No permission check needed here: This is just a wrapper around the |
| 1739 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1740 | // the UI before it does anything. |
| 1741 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1742 | final long identity = Binder.clearCallingIdentity(); |
| 1743 | try { |
| 1744 | String url = createTelUrl(number); |
| 1745 | if (url == null) { |
| 1746 | return; |
| 1747 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1748 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1749 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1750 | PhoneConstants.State state = mCM.getState(subId); |
| 1751 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1752 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1753 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1754 | mApp.startActivity(intent); |
| 1755 | } |
| 1756 | } finally { |
| 1757 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1758 | } |
| 1759 | } |
| 1760 | |
| 1761 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1762 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1765 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1766 | if (DBG) log("call: " + number); |
| 1767 | |
| 1768 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1769 | // need to do a permission check since we're calling startActivity() |
| 1770 | // from the context of the phone app. |
| 1771 | enforceCallPermission(); |
| 1772 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1773 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1774 | != AppOpsManager.MODE_ALLOWED) { |
| 1775 | return; |
| 1776 | } |
| 1777 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1778 | final long identity = Binder.clearCallingIdentity(); |
| 1779 | try { |
| 1780 | String url = createTelUrl(number); |
| 1781 | if (url == null) { |
| 1782 | return; |
| 1783 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1784 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1785 | boolean isValid = false; |
| 1786 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1787 | if (slist != null) { |
| 1788 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1789 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1790 | isValid = true; |
| 1791 | break; |
| 1792 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1793 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1794 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1795 | if (!isValid) { |
| 1796 | return; |
| 1797 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1798 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1799 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1800 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1801 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1802 | mApp.startActivity(intent); |
| 1803 | } finally { |
| 1804 | Binder.restoreCallingIdentity(identity); |
| 1805 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1808 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1809 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1810 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1811 | } |
| 1812 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1813 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1814 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1815 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1816 | } |
| 1817 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1818 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1819 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1820 | |
| 1821 | final long identity = Binder.clearCallingIdentity(); |
| 1822 | try { |
| 1823 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1824 | checkSimPin.start(); |
| 1825 | return checkSimPin.unlockSim(null, pin); |
| 1826 | } finally { |
| 1827 | Binder.restoreCallingIdentity(identity); |
| 1828 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1831 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1832 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1833 | |
| 1834 | final long identity = Binder.clearCallingIdentity(); |
| 1835 | try { |
| 1836 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1837 | checkSimPuk.start(); |
| 1838 | return checkSimPuk.unlockSim(puk, pin); |
| 1839 | } finally { |
| 1840 | Binder.restoreCallingIdentity(identity); |
| 1841 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1845 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1846 | * a synchronous one. |
| 1847 | */ |
| 1848 | private static class UnlockSim extends Thread { |
| 1849 | |
| 1850 | private final IccCard mSimCard; |
| 1851 | |
| 1852 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1853 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1854 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1855 | |
| 1856 | // For replies from SimCard interface |
| 1857 | private Handler mHandler; |
| 1858 | |
| 1859 | // For async handler to identify request type |
| 1860 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1861 | |
| 1862 | public UnlockSim(IccCard simCard) { |
| 1863 | mSimCard = simCard; |
| 1864 | } |
| 1865 | |
| 1866 | @Override |
| 1867 | public void run() { |
| 1868 | Looper.prepare(); |
| 1869 | synchronized (UnlockSim.this) { |
| 1870 | mHandler = new Handler() { |
| 1871 | @Override |
| 1872 | public void handleMessage(Message msg) { |
| 1873 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1874 | switch (msg.what) { |
| 1875 | case SUPPLY_PIN_COMPLETE: |
| 1876 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1877 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1878 | mRetryCount = msg.arg1; |
| 1879 | if (ar.exception != null) { |
| 1880 | if (ar.exception instanceof CommandException && |
| 1881 | ((CommandException)(ar.exception)).getCommandError() |
| 1882 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1883 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1884 | } else { |
| 1885 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1886 | } |
| 1887 | } else { |
| 1888 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1889 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | mDone = true; |
| 1891 | UnlockSim.this.notifyAll(); |
| 1892 | } |
| 1893 | break; |
| 1894 | } |
| 1895 | } |
| 1896 | }; |
| 1897 | UnlockSim.this.notifyAll(); |
| 1898 | } |
| 1899 | Looper.loop(); |
| 1900 | } |
| 1901 | |
| 1902 | /* |
| 1903 | * Use PIN or PUK to unlock SIM card |
| 1904 | * |
| 1905 | * If PUK is null, unlock SIM card with PIN |
| 1906 | * |
| 1907 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1908 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1909 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1910 | |
| 1911 | while (mHandler == null) { |
| 1912 | try { |
| 1913 | wait(); |
| 1914 | } catch (InterruptedException e) { |
| 1915 | Thread.currentThread().interrupt(); |
| 1916 | } |
| 1917 | } |
| 1918 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1919 | |
| 1920 | if (puk == null) { |
| 1921 | mSimCard.supplyPin(pin, callback); |
| 1922 | } else { |
| 1923 | mSimCard.supplyPuk(puk, pin, callback); |
| 1924 | } |
| 1925 | |
| 1926 | while (!mDone) { |
| 1927 | try { |
| 1928 | Log.d(LOG_TAG, "wait for done"); |
| 1929 | wait(); |
| 1930 | } catch (InterruptedException e) { |
| 1931 | // Restore the interrupted status |
| 1932 | Thread.currentThread().interrupt(); |
| 1933 | } |
| 1934 | } |
| 1935 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1936 | int[] resultArray = new int[2]; |
| 1937 | resultArray[0] = mResult; |
| 1938 | resultArray[1] = mRetryCount; |
| 1939 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1944 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1945 | |
| 1946 | } |
| 1947 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1948 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1949 | // No permission check needed here: this call is harmless, and it's |
| 1950 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1951 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1952 | final long identity = Binder.clearCallingIdentity(); |
| 1953 | try { |
| 1954 | final Phone phone = getPhone(subId); |
| 1955 | if (phone != null) { |
| 1956 | phone.updateServiceLocation(); |
| 1957 | } |
| 1958 | } finally { |
| 1959 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1960 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1963 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1964 | @Override |
| 1965 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1966 | return isRadioOnWithFeature(callingPackage, null); |
| 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | @Override |
| 1971 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1972 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1973 | callingFeatureId); |
| 1974 | } |
| 1975 | |
| 1976 | @Deprecated |
| 1977 | @Override |
| 1978 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1979 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1982 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1983 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1984 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1986 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1987 | return false; |
| 1988 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1989 | |
| 1990 | final long identity = Binder.clearCallingIdentity(); |
| 1991 | try { |
| 1992 | return isRadioOnForSubscriber(subId); |
| 1993 | } finally { |
| 1994 | Binder.restoreCallingIdentity(identity); |
| 1995 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1999 | final long identity = Binder.clearCallingIdentity(); |
| 2000 | try { |
| 2001 | final Phone phone = getPhone(subId); |
| 2002 | if (phone != null) { |
| 2003 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2004 | } else { |
| 2005 | return false; |
| 2006 | } |
| 2007 | } finally { |
| 2008 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2009 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2013 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2014 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2015 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2016 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2018 | |
| 2019 | final long identity = Binder.clearCallingIdentity(); |
| 2020 | try { |
| 2021 | final Phone phone = getPhone(subId); |
| 2022 | if (phone != null) { |
| 2023 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2024 | } |
| 2025 | } finally { |
| 2026 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2027 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2031 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2034 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2035 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2036 | |
| 2037 | final long identity = Binder.clearCallingIdentity(); |
| 2038 | try { |
| 2039 | final Phone phone = getPhone(subId); |
| 2040 | if (phone == null) { |
| 2041 | return false; |
| 2042 | } |
| 2043 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2044 | toggleRadioOnOffForSubscriber(subId); |
| 2045 | } |
| 2046 | return true; |
| 2047 | } finally { |
| 2048 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2049 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2050 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2051 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2052 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2053 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2054 | /* |
| 2055 | * If any of the Radios are available, it will need to be |
| 2056 | * shutdown. So return true if any Radio is available. |
| 2057 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2058 | final long identity = Binder.clearCallingIdentity(); |
| 2059 | try { |
| 2060 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2061 | Phone phone = PhoneFactory.getPhone(i); |
| 2062 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2063 | } |
| 2064 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2065 | return false; |
| 2066 | } finally { |
| 2067 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2068 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2071 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2072 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2073 | enforceModifyPermission(); |
| 2074 | |
| 2075 | final long identity = Binder.clearCallingIdentity(); |
| 2076 | try { |
| 2077 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2078 | logv("Shutting down Phone " + i); |
| 2079 | shutdownRadioUsingPhoneId(i); |
| 2080 | } |
| 2081 | } finally { |
| 2082 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2087 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2088 | if (phone != null && phone.isRadioAvailable()) { |
| 2089 | phone.shutdownRadio(); |
| 2090 | } |
| 2091 | } |
| 2092 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2094 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2095 | |
| 2096 | final long identity = Binder.clearCallingIdentity(); |
| 2097 | try { |
| 2098 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2099 | if (defaultPhone != null) { |
| 2100 | defaultPhone.setRadioPower(turnOn); |
| 2101 | return true; |
| 2102 | } else { |
| 2103 | loge("There's no default phone."); |
| 2104 | return false; |
| 2105 | } |
| 2106 | } finally { |
| 2107 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2108 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2111 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2112 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2113 | |
| 2114 | final long identity = Binder.clearCallingIdentity(); |
| 2115 | try { |
| 2116 | final Phone phone = getPhone(subId); |
| 2117 | if (phone != null) { |
| 2118 | phone.setRadioPower(turnOn); |
| 2119 | return true; |
| 2120 | } else { |
| 2121 | return false; |
| 2122 | } |
| 2123 | } finally { |
| 2124 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2125 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2128 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2129 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2130 | public boolean enableDataConnectivity() { |
| 2131 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2132 | |
| 2133 | final long identity = Binder.clearCallingIdentity(); |
| 2134 | try { |
| 2135 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2136 | final Phone phone = getPhone(subId); |
| 2137 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2138 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2139 | return true; |
| 2140 | } else { |
| 2141 | return false; |
| 2142 | } |
| 2143 | } finally { |
| 2144 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2145 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2148 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2149 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2150 | public boolean disableDataConnectivity() { |
| 2151 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2152 | |
| 2153 | final long identity = Binder.clearCallingIdentity(); |
| 2154 | try { |
| 2155 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2156 | final Phone phone = getPhone(subId); |
| 2157 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2158 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2159 | return true; |
| 2160 | } else { |
| 2161 | return false; |
| 2162 | } |
| 2163 | } finally { |
| 2164 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2165 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2168 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2169 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2170 | final long identity = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | final Phone phone = getPhone(subId); |
| 2173 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2174 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2175 | } else { |
| 2176 | return false; |
| 2177 | } |
| 2178 | } finally { |
| 2179 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2180 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2184 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2187 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2188 | enforceCallPermission(); |
| 2189 | |
| 2190 | final long identity = Binder.clearCallingIdentity(); |
| 2191 | try { |
| 2192 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2193 | return; |
| 2194 | } |
| 2195 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2196 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2197 | } finally { |
| 2198 | Binder.restoreCallingIdentity(identity); |
| 2199 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2200 | }; |
| 2201 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2202 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2203 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2204 | |
| 2205 | final long identity = Binder.clearCallingIdentity(); |
| 2206 | try { |
| 2207 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2208 | return false; |
| 2209 | } |
| 2210 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2211 | } finally { |
| 2212 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2213 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2217 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2220 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2221 | final long identity = Binder.clearCallingIdentity(); |
| 2222 | try { |
| 2223 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2224 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2225 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2226 | } finally { |
| 2227 | Binder.restoreCallingIdentity(identity); |
| 2228 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2231 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2232 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2233 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2234 | } |
| 2235 | |
| 2236 | @Override |
| 2237 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2238 | final long identity = Binder.clearCallingIdentity(); |
| 2239 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2240 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2241 | if (phone != null) { |
| 2242 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2243 | } else { |
| 2244 | return PhoneConstantConversions.convertDataState( |
| 2245 | PhoneConstants.DataState.DISCONNECTED); |
| 2246 | } |
| 2247 | } finally { |
| 2248 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2249 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2252 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2253 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2254 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2255 | } |
| 2256 | |
| 2257 | @Override |
| 2258 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2259 | final long identity = Binder.clearCallingIdentity(); |
| 2260 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2261 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2262 | if (phone != null) { |
| 2263 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2264 | } else { |
| 2265 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2266 | } |
| 2267 | } finally { |
| 2268 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2269 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2273 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2274 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2275 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2276 | |
| 2277 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2278 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2279 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2280 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2281 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2282 | .setCallingPid(Binder.getCallingPid()) |
| 2283 | .setCallingUid(Binder.getCallingUid()) |
| 2284 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2285 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2286 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2287 | .build()); |
| 2288 | switch (locationResult) { |
| 2289 | case DENIED_HARD: |
| 2290 | throw new SecurityException("Not allowed to access cell location"); |
| 2291 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2292 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2293 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2296 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2297 | final long identity = Binder.clearCallingIdentity(); |
| 2298 | try { |
| 2299 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2300 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2301 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2302 | } finally { |
| 2303 | Binder.restoreCallingIdentity(identity); |
| 2304 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2307 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2308 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2309 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2310 | // registered cell info, so return a NULL country instead. |
| 2311 | final long identity = Binder.clearCallingIdentity(); |
| 2312 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2313 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2314 | // Get default phone in this case. |
| 2315 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2316 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2317 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2318 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2319 | if (phone == null) return ""; |
| 2320 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2321 | if (sst == null) return ""; |
| 2322 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2323 | if (lt == null) return ""; |
| 2324 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2325 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2326 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2327 | } finally { |
| 2328 | Binder.restoreCallingIdentity(identity); |
| 2329 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2334 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2337 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2338 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2339 | mApp.enforceCallingOrSelfPermission( |
| 2340 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2341 | |
| 2342 | final long identity = Binder.clearCallingIdentity(); |
| 2343 | try { |
| 2344 | final Phone phone = getPhone(subId); |
| 2345 | if (phone != null) { |
| 2346 | phone.enableLocationUpdates(); |
| 2347 | } |
| 2348 | } finally { |
| 2349 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2350 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | @Override |
| 2354 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2355 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2358 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2359 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | mApp.enforceCallingOrSelfPermission( |
| 2361 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2362 | |
| 2363 | final long identity = Binder.clearCallingIdentity(); |
| 2364 | try { |
| 2365 | final Phone phone = getPhone(subId); |
| 2366 | if (phone != null) { |
| 2367 | phone.disableLocationUpdates(); |
| 2368 | } |
| 2369 | } finally { |
| 2370 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2371 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2374 | /** |
| 2375 | * Returns the target SDK version number for a given package name. |
| 2376 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2377 | * This call MUST be invoked before clearing the calling UID. |
| 2378 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2379 | * @return target SDK if the package is found or INT_MAX. |
| 2380 | */ |
| 2381 | private int getTargetSdk(String packageName) { |
| 2382 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2383 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2384 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2385 | if (ai != null) return ai.targetSdkVersion; |
| 2386 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2387 | loge("Failed to get package info for pkg=" |
| 2388 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2389 | } |
| 2390 | return Integer.MAX_VALUE; |
| 2391 | } |
| 2392 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | @Override |
| 2394 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2395 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2396 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2397 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2398 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2399 | throw new SecurityException( |
| 2400 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2401 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2402 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2403 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2404 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2405 | return null; |
| 2406 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2407 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2408 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2409 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2410 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2411 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2412 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2413 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2414 | for (CellInfo ci : info) { |
| 2415 | if (ci instanceof CellInfoGsm) { |
| 2416 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2417 | } else if (ci instanceof CellInfoWcdma) { |
| 2418 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2419 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2420 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2421 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2424 | private List<CellInfo> getCachedCellInfo() { |
| 2425 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2426 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2427 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2428 | if (info != null) cellInfos.addAll(info); |
| 2429 | } |
| 2430 | return cellInfos; |
| 2431 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2432 | |
| 2433 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2434 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2435 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2436 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2437 | |
| 2438 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2439 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2440 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2441 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2442 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2443 | .setCallingPid(Binder.getCallingPid()) |
| 2444 | .setCallingUid(Binder.getCallingUid()) |
| 2445 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2446 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2447 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2448 | .build()); |
| 2449 | switch (locationResult) { |
| 2450 | case DENIED_HARD: |
| 2451 | throw new SecurityException("Not allowed to access cell info"); |
| 2452 | case DENIED_SOFT: |
| 2453 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2456 | final int targetSdk = getTargetSdk(callingPackage); |
| 2457 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2458 | return getCachedCellInfo(); |
| 2459 | } |
| 2460 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2461 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2462 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2463 | final long identity = Binder.clearCallingIdentity(); |
| 2464 | try { |
| 2465 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2466 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2467 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2468 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 | if (info != null) cellInfos.addAll(info); |
| 2470 | } |
| 2471 | return cellInfos; |
| 2472 | } finally { |
| 2473 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2474 | } |
| 2475 | } |
| 2476 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2477 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2478 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2479 | String callingFeatureId) { |
| 2480 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2481 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2485 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2486 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2487 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2488 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2491 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2492 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2493 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2494 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2495 | |
| 2496 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2497 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2498 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2499 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2500 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2501 | .setCallingPid(Binder.getCallingPid()) |
| 2502 | .setCallingUid(Binder.getCallingUid()) |
| 2503 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2504 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2505 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2506 | .build()); |
| 2507 | switch (locationResult) { |
| 2508 | case DENIED_HARD: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2509 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2510 | // Safetynet logging for b/154934934 |
| 2511 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2512 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2513 | throw new SecurityException("Not allowed to access cell info"); |
| 2514 | case DENIED_SOFT: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2515 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2516 | // Safetynet logging for b/154934934 |
| 2517 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2518 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2519 | try { |
| 2520 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2521 | } catch (RemoteException re) { |
| 2522 | // Drop without consequences |
| 2523 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2524 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2527 | |
| 2528 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2529 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2530 | |
| 2531 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2532 | } |
| 2533 | |
| 2534 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2535 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2536 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2537 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2538 | |
| 2539 | final long identity = Binder.clearCallingIdentity(); |
| 2540 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2541 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | } finally { |
| 2543 | Binder.restoreCallingIdentity(identity); |
| 2544 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2547 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2548 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2549 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2550 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2551 | return null; |
| 2552 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2553 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2554 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2555 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2556 | return null; |
| 2557 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2558 | |
| 2559 | final long identity = Binder.clearCallingIdentity(); |
| 2560 | try { |
| 2561 | return phone.getImei(); |
| 2562 | } finally { |
| 2563 | Binder.restoreCallingIdentity(identity); |
| 2564 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2568 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2569 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2570 | String tac = null; |
| 2571 | if (phone != null) { |
| 2572 | String imei = phone.getImei(); |
| 2573 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2574 | } |
| 2575 | return tac; |
| 2576 | } |
| 2577 | |
| 2578 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2579 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2580 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2581 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2582 | return null; |
| 2583 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2584 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2585 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2586 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2587 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2588 | return null; |
| 2589 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | |
| 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
| 2593 | return phone.getMeid(); |
| 2594 | } finally { |
| 2595 | Binder.restoreCallingIdentity(identity); |
| 2596 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2600 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2601 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2602 | String manufacturerCode = null; |
| 2603 | if (phone != null) { |
| 2604 | String meid = phone.getMeid(); |
| 2605 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2606 | } |
| 2607 | return manufacturerCode; |
| 2608 | } |
| 2609 | |
| 2610 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2611 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2612 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2613 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2614 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2615 | return null; |
| 2616 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2617 | int subId = phone.getSubId(); |
| 2618 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2619 | mApp, subId, callingPackage, callingFeatureId, |
| 2620 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2621 | return null; |
| 2622 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | |
| 2624 | final long identity = Binder.clearCallingIdentity(); |
| 2625 | try { |
| 2626 | return phone.getDeviceSvn(); |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
| 2629 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2632 | @Override |
| 2633 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2634 | final long identity = Binder.clearCallingIdentity(); |
| 2635 | try { |
| 2636 | final Phone phone = getPhone(subId); |
| 2637 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2638 | } finally { |
| 2639 | Binder.restoreCallingIdentity(identity); |
| 2640 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | @Override |
| 2644 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2645 | final long identity = Binder.clearCallingIdentity(); |
| 2646 | try { |
| 2647 | final Phone phone = getPhone(subId); |
| 2648 | return phone == null ? null : phone.getCarrierName(); |
| 2649 | } finally { |
| 2650 | Binder.restoreCallingIdentity(identity); |
| 2651 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2652 | } |
| 2653 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2654 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2655 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2656 | final long identity = Binder.clearCallingIdentity(); |
| 2657 | try { |
| 2658 | final Phone phone = getPhone(subId); |
| 2659 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2660 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
| 2663 | } |
| 2664 | } |
| 2665 | |
| 2666 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2667 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2668 | final long identity = Binder.clearCallingIdentity(); |
| 2669 | try { |
| 2670 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2671 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(identity); |
| 2674 | } |
| 2675 | } |
| 2676 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2677 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2678 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2679 | if (!isSubscriptionMccMnc) { |
| 2680 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2681 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2682 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2683 | if (phone == null) { |
| 2684 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2685 | } |
| 2686 | final long identity = Binder.clearCallingIdentity(); |
| 2687 | try { |
| 2688 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2689 | } finally { |
| 2690 | Binder.restoreCallingIdentity(identity); |
| 2691 | } |
| 2692 | } |
| 2693 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | // |
| 2695 | // Internal helper methods. |
| 2696 | // |
| 2697 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2698 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2699 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2700 | * |
| 2701 | * @throws SecurityException if the caller does not have the required permission |
| 2702 | */ |
| 2703 | private void enforceModifyPermission() { |
| 2704 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2705 | } |
| 2706 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2707 | /** |
| 2708 | * Make sure the caller is system. |
| 2709 | * |
| 2710 | * @throws SecurityException if the caller is not system. |
| 2711 | */ |
| 2712 | private void enforceSystemCaller() { |
| 2713 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2714 | throw new SecurityException("Caller must be system"); |
| 2715 | } |
| 2716 | } |
| 2717 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2718 | private void enforceActiveEmergencySessionPermission() { |
| 2719 | mApp.enforceCallingOrSelfPermission( |
| 2720 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2721 | } |
| 2722 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2723 | /** |
| 2724 | * Make sure the caller has the CALL_PHONE permission. |
| 2725 | * |
| 2726 | * @throws SecurityException if the caller does not have the required permission |
| 2727 | */ |
| 2728 | private void enforceCallPermission() { |
| 2729 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2730 | } |
| 2731 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2732 | private void enforceSettingsPermission() { |
| 2733 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | private String createTelUrl(String number) { |
| 2737 | if (TextUtils.isEmpty(number)) { |
| 2738 | return null; |
| 2739 | } |
| 2740 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2741 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2744 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2745 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2746 | } |
| 2747 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2748 | private static void logv(String msg) { |
| 2749 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2750 | } |
| 2751 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2752 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2753 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2754 | } |
| 2755 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2756 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2757 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2758 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2761 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2762 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2763 | final long identity = Binder.clearCallingIdentity(); |
| 2764 | try { |
| 2765 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2766 | if (phone == null) { |
| 2767 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2768 | } else { |
| 2769 | return phone.getPhoneType(); |
| 2770 | } |
| 2771 | } finally { |
| 2772 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2773 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | /** |
| 2777 | * Returns the CDMA ERI icon index to display |
| 2778 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2779 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2780 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2781 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2782 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2785 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2786 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2787 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2788 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2789 | mApp, subId, callingPackage, callingFeatureId, |
| 2790 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2791 | return -1; |
| 2792 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2793 | |
| 2794 | final long identity = Binder.clearCallingIdentity(); |
| 2795 | try { |
| 2796 | final Phone phone = getPhone(subId); |
| 2797 | if (phone != null) { |
| 2798 | return phone.getCdmaEriIconIndex(); |
| 2799 | } else { |
| 2800 | return -1; |
| 2801 | } |
| 2802 | } finally { |
| 2803 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2804 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | /** |
| 2808 | * Returns the CDMA ERI icon mode, |
| 2809 | * 0 - ON |
| 2810 | * 1 - FLASHING |
| 2811 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2812 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2813 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2814 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2815 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2816 | } |
| 2817 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2818 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2819 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2820 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2821 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2822 | mApp, subId, callingPackage, callingFeatureId, |
| 2823 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2824 | return -1; |
| 2825 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | |
| 2827 | final long identity = Binder.clearCallingIdentity(); |
| 2828 | try { |
| 2829 | final Phone phone = getPhone(subId); |
| 2830 | if (phone != null) { |
| 2831 | return phone.getCdmaEriIconMode(); |
| 2832 | } else { |
| 2833 | return -1; |
| 2834 | } |
| 2835 | } finally { |
| 2836 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | /** |
| 2841 | * Returns the CDMA ERI text, |
| 2842 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2843 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2844 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2845 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2846 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2849 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2850 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2851 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2852 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2853 | mApp, subId, callingPackage, callingFeatureId, |
| 2854 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2855 | return null; |
| 2856 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2857 | |
| 2858 | final long identity = Binder.clearCallingIdentity(); |
| 2859 | try { |
| 2860 | final Phone phone = getPhone(subId); |
| 2861 | if (phone != null) { |
| 2862 | return phone.getCdmaEriText(); |
| 2863 | } else { |
| 2864 | return null; |
| 2865 | } |
| 2866 | } finally { |
| 2867 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2868 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2872 | * Returns the CDMA MDN. |
| 2873 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2874 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2875 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2876 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2877 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | |
| 2879 | final long identity = Binder.clearCallingIdentity(); |
| 2880 | try { |
| 2881 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2882 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2883 | return phone.getLine1Number(); |
| 2884 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2885 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2886 | return null; |
| 2887 | } |
| 2888 | } finally { |
| 2889 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2890 | } |
| 2891 | } |
| 2892 | |
| 2893 | /** |
| 2894 | * Returns the CDMA MIN. |
| 2895 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2896 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2897 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2899 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2900 | |
| 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
| 2903 | final Phone phone = getPhone(subId); |
| 2904 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2905 | return phone.getCdmaMin(); |
| 2906 | } else { |
| 2907 | return null; |
| 2908 | } |
| 2909 | } finally { |
| 2910 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2914 | @Override |
| 2915 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2916 | INumberVerificationCallback callback, String callingPackage) { |
| 2917 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2918 | != PERMISSION_GRANTED) { |
| 2919 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2920 | } |
| 2921 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2922 | |
| 2923 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2924 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2925 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2926 | } |
| 2927 | |
| 2928 | if (range == null) { |
| 2929 | throw new NullPointerException("Range must be non-null"); |
| 2930 | } |
| 2931 | |
| 2932 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2933 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2934 | |
| 2935 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2936 | } |
| 2937 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2938 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2939 | * Returns true if CDMA provisioning needs to run. |
| 2940 | */ |
| 2941 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2942 | final long identity = Binder.clearCallingIdentity(); |
| 2943 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2944 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2945 | } finally { |
| 2946 | Binder.restoreCallingIdentity(identity); |
| 2947 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2951 | * Sets the voice mail number of a given subId. |
| 2952 | */ |
| 2953 | @Override |
| 2954 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2955 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2956 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | |
| 2958 | final long identity = Binder.clearCallingIdentity(); |
| 2959 | try { |
| 2960 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2961 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2962 | return success; |
| 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(identity); |
| 2965 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2966 | } |
| 2967 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2968 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2969 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2970 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2971 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2972 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2973 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2974 | throw new SecurityException("caller must be system dialer"); |
| 2975 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | |
| 2977 | final long identity = Binder.clearCallingIdentity(); |
| 2978 | try { |
| 2979 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2980 | if (phoneAccountHandle == null) { |
| 2981 | return null; |
| 2982 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2983 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2984 | } finally { |
| 2985 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2986 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2990 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2991 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2992 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2993 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2994 | mApp, subId, callingPackage, callingFeatureId, |
| 2995 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2996 | return null; |
| 2997 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2999 | final long identity = Binder.clearCallingIdentity(); |
| 3000 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3001 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3002 | } finally { |
| 3003 | Binder.restoreCallingIdentity(identity); |
| 3004 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3008 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3009 | VisualVoicemailSmsFilterSettings settings) { |
| 3010 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3011 | |
| 3012 | final long identity = Binder.clearCallingIdentity(); |
| 3013 | try { |
| 3014 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3015 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3022 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3023 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3024 | |
| 3025 | final long identity = Binder.clearCallingIdentity(); |
| 3026 | try { |
| 3027 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3028 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | } finally { |
| 3030 | Binder.restoreCallingIdentity(identity); |
| 3031 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3035 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3036 | String callingPackage, int subId) { |
| 3037 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3038 | |
| 3039 | final long identity = Binder.clearCallingIdentity(); |
| 3040 | try { |
| 3041 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3042 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3043 | } finally { |
| 3044 | Binder.restoreCallingIdentity(identity); |
| 3045 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3049 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3050 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | |
| 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
| 3054 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3055 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3056 | } finally { |
| 3057 | Binder.restoreCallingIdentity(identity); |
| 3058 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | @Override |
Philip P. Moltmann | acc6364 | 2020-03-19 21:37:01 +0000 | [diff] [blame] | 3062 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3063 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3064 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3065 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3066 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3067 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3068 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | acc6364 | 2020-03-19 21:37:01 +0000 | [diff] [blame] | 3069 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3070 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3071 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3072 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3073 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3074 | * Sets the voice activation state of a given subId. |
| 3075 | */ |
| 3076 | @Override |
| 3077 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3078 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3079 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3080 | |
| 3081 | final long identity = Binder.clearCallingIdentity(); |
| 3082 | try { |
| 3083 | final Phone phone = getPhone(subId); |
| 3084 | if (phone != null) { |
| 3085 | phone.setVoiceActivationState(activationState); |
| 3086 | } else { |
| 3087 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3088 | } |
| 3089 | } finally { |
| 3090 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | /** |
| 3095 | * Sets the data activation state of a given subId. |
| 3096 | */ |
| 3097 | @Override |
| 3098 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3100 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3101 | |
| 3102 | final long identity = Binder.clearCallingIdentity(); |
| 3103 | try { |
| 3104 | final Phone phone = getPhone(subId); |
| 3105 | if (phone != null) { |
| 3106 | phone.setDataActivationState(activationState); |
| 3107 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3108 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3109 | } |
| 3110 | } finally { |
| 3111 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | /** |
| 3116 | * Returns the voice activation state of a given subId. |
| 3117 | */ |
| 3118 | @Override |
| 3119 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3120 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3121 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3122 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3123 | final long identity = Binder.clearCallingIdentity(); |
| 3124 | try { |
| 3125 | if (phone != null) { |
| 3126 | return phone.getVoiceActivationState(); |
| 3127 | } else { |
| 3128 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3129 | } |
| 3130 | } finally { |
| 3131 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | /** |
| 3136 | * Returns the data activation state of a given subId. |
| 3137 | */ |
| 3138 | @Override |
| 3139 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3140 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3141 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3142 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3143 | final long identity = Binder.clearCallingIdentity(); |
| 3144 | try { |
| 3145 | if (phone != null) { |
| 3146 | return phone.getDataActivationState(); |
| 3147 | } else { |
| 3148 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3149 | } |
| 3150 | } finally { |
| 3151 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3152 | } |
| 3153 | } |
| 3154 | |
| 3155 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3156 | * Returns the unread count of voicemails for a subId |
| 3157 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3158 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3159 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3160 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3161 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3162 | mApp, subId, callingPackage, callingFeatureId, |
| 3163 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3164 | return 0; |
| 3165 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3166 | final long identity = Binder.clearCallingIdentity(); |
| 3167 | try { |
| 3168 | final Phone phone = getPhone(subId); |
| 3169 | if (phone != null) { |
| 3170 | return phone.getVoiceMessageCount(); |
| 3171 | } else { |
| 3172 | return 0; |
| 3173 | } |
| 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3176 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3180 | * returns true, if the device is in a state where both voice and data |
| 3181 | * are supported simultaneously. This can change based on location or network condition. |
| 3182 | */ |
| 3183 | @Override |
| 3184 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3185 | final long identity = Binder.clearCallingIdentity(); |
| 3186 | try { |
| 3187 | final Phone phone = getPhone(subId); |
| 3188 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3189 | } finally { |
| 3190 | Binder.restoreCallingIdentity(identity); |
| 3191 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3195 | * Send the dialer code if called from the current default dialer or the caller has |
| 3196 | * carrier privilege. |
| 3197 | * @param inputCode The dialer code to send |
| 3198 | */ |
| 3199 | @Override |
| 3200 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3201 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3202 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3203 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3204 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3205 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3206 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3207 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3209 | |
| 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3212 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3213 | } finally { |
| 3214 | Binder.restoreCallingIdentity(identity); |
| 3215 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3216 | } |
| 3217 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3218 | @Override |
| 3219 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3220 | TelephonyPermissions |
| 3221 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3222 | mApp, subId, "getNetworkSelectionMode"); |
| 3223 | final long identity = Binder.clearCallingIdentity(); |
| 3224 | try { |
| 3225 | if (!isActiveSubscription(subId)) { |
| 3226 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3227 | } |
| 3228 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3231 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3234 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3235 | public boolean isInEmergencySmsMode() { |
| 3236 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3237 | final long identity = Binder.clearCallingIdentity(); |
| 3238 | try { |
| 3239 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3240 | if (phone.isInEmergencySmsMode()) { |
| 3241 | return true; |
| 3242 | } |
| 3243 | } |
| 3244 | } finally { |
| 3245 | Binder.restoreCallingIdentity(identity); |
| 3246 | } |
| 3247 | return false; |
| 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 | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3255 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3256 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3257 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3258 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3259 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3260 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3261 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3262 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3263 | "IMS not available on device."); |
| 3264 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3265 | final long token = Binder.clearCallingIdentity(); |
| 3266 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3267 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3268 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3269 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3270 | } catch (ImsException e) { |
| 3271 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3272 | } finally { |
| 3273 | Binder.restoreCallingIdentity(token); |
| 3274 | } |
| 3275 | } |
| 3276 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3277 | /** |
| 3278 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3279 | * @param subId The subscription to use to check the configuration. |
| 3280 | * @param c The callback that will be used to send the result. |
| 3281 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3282 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3283 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3284 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3285 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3286 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3287 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3288 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3289 | final long token = Binder.clearCallingIdentity(); |
| 3290 | try { |
| 3291 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3292 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3293 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3294 | } catch (ImsException e) { |
| 3295 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3296 | + "is inactive, ignoring unregister."); |
| 3297 | // If the subscription is no longer active, just return, since the callback |
| 3298 | // will already have been removed internally. |
| 3299 | } finally { |
| 3300 | Binder.restoreCallingIdentity(token); |
| 3301 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3302 | } |
| 3303 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3304 | /** |
| 3305 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3306 | */ |
| 3307 | @Override |
| 3308 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3309 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3310 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3311 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3312 | "IMS not available on device."); |
| 3313 | } |
| 3314 | final long token = Binder.clearCallingIdentity(); |
| 3315 | try { |
| 3316 | Phone phone = getPhone(subId); |
| 3317 | if (phone == null) { |
| 3318 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3319 | + subId + "'"); |
| 3320 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3321 | } |
| 3322 | phone.getImsRegistrationState(regState -> { |
| 3323 | try { |
| 3324 | consumer.accept((regState == null) |
| 3325 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3326 | } catch (RemoteException e) { |
| 3327 | // Ignore if the remote process is no longer available to call back. |
| 3328 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3329 | } |
| 3330 | }); |
| 3331 | } finally { |
| 3332 | Binder.restoreCallingIdentity(token); |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | /** |
| 3337 | * Get the transport type for the IMS service registration state. |
| 3338 | */ |
| 3339 | @Override |
| 3340 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3341 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3342 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3343 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3344 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3345 | "IMS not available on device."); |
| 3346 | } |
| 3347 | final long token = Binder.clearCallingIdentity(); |
| 3348 | try { |
| 3349 | Phone phone = getPhone(subId); |
| 3350 | if (phone == null) { |
| 3351 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3352 | + subId + "'"); |
| 3353 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3354 | } |
| 3355 | phone.getImsRegistrationTech(regTech -> { |
| 3356 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3357 | int regTechConverted = (regTech == null) |
| 3358 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3359 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3360 | regTechConverted); |
| 3361 | try { |
| 3362 | consumer.accept(regTechConverted); |
| 3363 | } catch (RemoteException e) { |
| 3364 | // Ignore if the remote process is no longer available to call back. |
| 3365 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3366 | } |
| 3367 | }); |
| 3368 | } finally { |
| 3369 | Binder.restoreCallingIdentity(token); |
| 3370 | } |
| 3371 | } |
| 3372 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3373 | /** |
| 3374 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3375 | * @param subId The subscription to use to check the configuration. |
| 3376 | * @param c The callback that will be used to send the result. |
| 3377 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3378 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3379 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3380 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3381 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3382 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3383 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3384 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3385 | "IMS not available on device."); |
| 3386 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3387 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3388 | final long token = Binder.clearCallingIdentity(); |
| 3389 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3390 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3391 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3392 | } catch (ImsException e) { |
| 3393 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3394 | } finally { |
| 3395 | Binder.restoreCallingIdentity(token); |
| 3396 | } |
| 3397 | } |
| 3398 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3399 | /** |
| 3400 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3401 | * @param subId The subscription to use to check the configuration. |
| 3402 | * @param c The callback that will be used to send the result. |
| 3403 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3404 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3405 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3406 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3407 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3408 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3409 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3410 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3411 | |
| 3412 | final long token = Binder.clearCallingIdentity(); |
| 3413 | try { |
| 3414 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3415 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3416 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3417 | } catch (ImsException e) { |
| 3418 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3419 | + "is inactive, ignoring unregister."); |
| 3420 | // If the subscription is no longer active, just return, since the callback |
| 3421 | // will already have been removed internally. |
| 3422 | } finally { |
| 3423 | Binder.restoreCallingIdentity(token); |
| 3424 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3428 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3429 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3430 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3431 | final long token = Binder.clearCallingIdentity(); |
| 3432 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3433 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3434 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3435 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3436 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3437 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3438 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3439 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3440 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3441 | } finally { |
| 3442 | Binder.restoreCallingIdentity(token); |
| 3443 | } |
| 3444 | } |
| 3445 | |
| 3446 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3447 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3448 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3449 | final long token = Binder.clearCallingIdentity(); |
| 3450 | try { |
| 3451 | Phone phone = getPhone(subId); |
| 3452 | if (phone == null) return false; |
| 3453 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3454 | } catch (com.android.ims.ImsException e) { |
| 3455 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3456 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3457 | } finally { |
| 3458 | Binder.restoreCallingIdentity(token); |
| 3459 | } |
| 3460 | } |
| 3461 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3462 | /** |
| 3463 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3464 | * subscription. |
| 3465 | * @param subId The subscription to use to check the configuration. |
| 3466 | * @param callback The callback that will be used to send the result. |
| 3467 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3468 | * @param transportType The transport type of the MmTelFeature capability. |
| 3469 | */ |
| 3470 | @Override |
| 3471 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3472 | int transportType) { |
| 3473 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3474 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3475 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3476 | "IMS not available on device."); |
| 3477 | } |
| 3478 | final long token = Binder.clearCallingIdentity(); |
| 3479 | try { |
| 3480 | int slotId = getSlotIndex(subId); |
| 3481 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3482 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3483 | + subId + "'"); |
| 3484 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3485 | } |
| 3486 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3487 | transportType, aBoolean -> { |
| 3488 | try { |
| 3489 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3490 | } catch (RemoteException e) { |
| 3491 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3492 | + "running. Ignore"); |
| 3493 | } |
| 3494 | }); |
| 3495 | } finally { |
| 3496 | Binder.restoreCallingIdentity(token); |
| 3497 | } |
| 3498 | } |
| 3499 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3500 | /** |
| 3501 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3502 | * @param subId The subscription to use to check the configuration. |
| 3503 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3504 | @Override |
| 3505 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3506 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3507 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3508 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3509 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3510 | final long token = Binder.clearCallingIdentity(); |
| 3511 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3512 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3513 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3514 | } catch (ImsException e) { |
| 3515 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3516 | } finally { |
| 3517 | Binder.restoreCallingIdentity(token); |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3522 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3524 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3525 | final long identity = Binder.clearCallingIdentity(); |
| 3526 | try { |
| 3527 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3528 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3529 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3530 | } catch (ImsException e) { |
| 3531 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3532 | } finally { |
| 3533 | Binder.restoreCallingIdentity(identity); |
| 3534 | } |
| 3535 | } |
| 3536 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3537 | /** |
| 3538 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3539 | * @param subId The subscription to use to check the configuration. |
| 3540 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3541 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3542 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3543 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3544 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3545 | final long identity = Binder.clearCallingIdentity(); |
| 3546 | try { |
| 3547 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3548 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3549 | } catch (ImsException e) { |
| 3550 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3557 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3559 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3560 | final long identity = Binder.clearCallingIdentity(); |
| 3561 | try { |
| 3562 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3563 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3564 | } catch (ImsException e) { |
| 3565 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3566 | } finally { |
| 3567 | Binder.restoreCallingIdentity(identity); |
| 3568 | } |
| 3569 | } |
| 3570 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3571 | /** |
| 3572 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3573 | * @param subId The subscription to use to check the configuration. |
| 3574 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3575 | @Override |
| 3576 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3577 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3578 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3579 | final long identity = Binder.clearCallingIdentity(); |
| 3580 | try { |
| 3581 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3582 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3583 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3584 | } catch (ImsException e) { |
| 3585 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(identity); |
| 3588 | } |
| 3589 | } |
| 3590 | |
| 3591 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3592 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3593 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3594 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3595 | final long identity = Binder.clearCallingIdentity(); |
| 3596 | try { |
| 3597 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3598 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3599 | } catch (ImsException e) { |
| 3600 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3601 | } finally { |
| 3602 | Binder.restoreCallingIdentity(identity); |
| 3603 | } |
| 3604 | } |
| 3605 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3606 | /** |
| 3607 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3608 | * @param subId The subscription to use to check the configuration. |
| 3609 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3610 | @Override |
| 3611 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3612 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3613 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3614 | final long identity = Binder.clearCallingIdentity(); |
| 3615 | try { |
| 3616 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3617 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3618 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3619 | } catch (ImsException e) { |
| 3620 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3621 | } finally { |
| 3622 | Binder.restoreCallingIdentity(identity); |
| 3623 | } |
| 3624 | } |
| 3625 | |
| 3626 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3627 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3629 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3630 | final long identity = Binder.clearCallingIdentity(); |
| 3631 | try { |
| 3632 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3633 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3634 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3635 | } catch (ImsException e) { |
| 3636 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3637 | } finally { |
| 3638 | Binder.restoreCallingIdentity(identity); |
| 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | @Override |
| 3643 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3645 | "setVoWiFiNonPersistent"); |
| 3646 | final long identity = Binder.clearCallingIdentity(); |
| 3647 | try { |
| 3648 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3649 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3650 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3651 | } catch (ImsException e) { |
| 3652 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3653 | } finally { |
| 3654 | Binder.restoreCallingIdentity(identity); |
| 3655 | } |
| 3656 | } |
| 3657 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3658 | /** |
| 3659 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3660 | * @param subId The subscription to use to check the configuration. |
| 3661 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3662 | @Override |
| 3663 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3664 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3665 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3666 | final long identity = Binder.clearCallingIdentity(); |
| 3667 | try { |
| 3668 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3669 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3670 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3671 | } catch (ImsException e) { |
| 3672 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3673 | } finally { |
| 3674 | Binder.restoreCallingIdentity(identity); |
| 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | @Override |
| 3679 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3681 | "setVoWiFiModeSetting"); |
| 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3685 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3686 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3687 | } catch (ImsException e) { |
| 3688 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(identity); |
| 3691 | } |
| 3692 | } |
| 3693 | |
| 3694 | @Override |
| 3695 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3696 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3697 | final long identity = Binder.clearCallingIdentity(); |
| 3698 | try { |
| 3699 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3700 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3701 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3702 | } catch (ImsException e) { |
| 3703 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3704 | } finally { |
| 3705 | Binder.restoreCallingIdentity(identity); |
| 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | @Override |
| 3710 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3712 | "setVoWiFiRoamingModeSetting"); |
| 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3716 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3717 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3718 | } catch (ImsException e) { |
| 3719 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3720 | } finally { |
| 3721 | Binder.restoreCallingIdentity(identity); |
| 3722 | } |
| 3723 | } |
| 3724 | |
| 3725 | @Override |
| 3726 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3728 | "setRttCapabilityEnabled"); |
| 3729 | final long identity = Binder.clearCallingIdentity(); |
| 3730 | try { |
| 3731 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3732 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3733 | } catch (ImsException e) { |
| 3734 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3735 | } finally { |
| 3736 | Binder.restoreCallingIdentity(identity); |
| 3737 | } |
| 3738 | } |
| 3739 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3740 | /** |
| 3741 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3742 | * @param subId The subscription to use to check the configuration. |
| 3743 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3744 | @Override |
| 3745 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3746 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3747 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3748 | final long identity = Binder.clearCallingIdentity(); |
| 3749 | try { |
| 3750 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3751 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3752 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3753 | } catch (ImsException e) { |
| 3754 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3755 | } finally { |
| 3756 | Binder.restoreCallingIdentity(identity); |
| 3757 | } |
| 3758 | } |
| 3759 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3760 | @Override |
| 3761 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3762 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3763 | final long identity = Binder.clearCallingIdentity(); |
| 3764 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3765 | if (!isImsAvailableOnDevice()) { |
| 3766 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3767 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3768 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3769 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3770 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3771 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3772 | } catch (ImsException e) { |
| 3773 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3774 | } finally { |
| 3775 | Binder.restoreCallingIdentity(identity); |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | @Override |
| 3780 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3781 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3782 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3783 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3784 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3785 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3786 | try { |
| 3787 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3788 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3789 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3790 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3791 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3792 | + "is inactive, ignoring unregister."); |
| 3793 | // If the subscription is no longer active, just return, since the callback will already |
| 3794 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3795 | } finally { |
| 3796 | Binder.restoreCallingIdentity(identity); |
| 3797 | } |
| 3798 | } |
| 3799 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3800 | |
| 3801 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3802 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3803 | message); |
| 3804 | } |
| 3805 | |
| 3806 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3807 | boolean isMmtelCapability) { |
| 3808 | Phone phone = getPhone(subId); |
| 3809 | if (phone == null) { |
| 3810 | loge("phone instance null for subid " + subId); |
| 3811 | return false; |
| 3812 | } |
| 3813 | if (isMmtelCapability) { |
| 3814 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3815 | return false; |
| 3816 | } |
| 3817 | } else { |
| 3818 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3819 | return false; |
| 3820 | } |
| 3821 | } |
| 3822 | return true; |
| 3823 | } |
| 3824 | |
| 3825 | @Override |
| 3826 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3827 | boolean isProvisioned) { |
| 3828 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3829 | |
| 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; |
| 3835 | } |
| 3836 | |
| 3837 | // this capability requires provisioning, route to the correct API. |
| 3838 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3839 | switch (capability) { |
| 3840 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3841 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3842 | ims.setEabProvisioned(isProvisioned); |
| 3843 | break; |
| 3844 | default: { |
| 3845 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3846 | + "rcs capability '" + capability + "', which does not require " |
| 3847 | + "provisioning."); |
| 3848 | } |
| 3849 | } |
| 3850 | } finally { |
| 3851 | Binder.restoreCallingIdentity(identity); |
| 3852 | } |
| 3853 | |
| 3854 | } |
| 3855 | |
| 3856 | |
| 3857 | @Override |
| 3858 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3859 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3860 | final long identity = Binder.clearCallingIdentity(); |
| 3861 | try { |
| 3862 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3863 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3864 | return true; |
| 3865 | } |
| 3866 | |
| 3867 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3868 | switch (capability) { |
| 3869 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3870 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3871 | return ims.isEabProvisionedOnDevice(); |
| 3872 | |
| 3873 | default: { |
| 3874 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3875 | + "capability '" + capability + "', which does not require " |
| 3876 | + "provisioning."); |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | } finally { |
| 3881 | Binder.restoreCallingIdentity(identity); |
| 3882 | } |
| 3883 | } |
| 3884 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3885 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3886 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3887 | boolean isProvisioned) { |
| 3888 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3889 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3890 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3891 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3892 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3893 | final long identity = Binder.clearCallingIdentity(); |
| 3894 | try { |
| 3895 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3896 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3897 | return; |
| 3898 | } |
| 3899 | |
| 3900 | // this capability requires provisioning, route to the correct API. |
| 3901 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3902 | switch (capability) { |
| 3903 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3904 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3905 | ims.setVolteProvisioned(isProvisioned); |
| 3906 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3907 | ims.setWfcProvisioned(isProvisioned); |
| 3908 | } |
| 3909 | break; |
| 3910 | } |
| 3911 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3912 | // There is currently no difference in VT provisioning type. |
| 3913 | ims.setVtProvisioned(isProvisioned); |
| 3914 | break; |
| 3915 | } |
| 3916 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3917 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3918 | // change the capability of the feature instead if needed. |
| 3919 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3920 | == isProvisioned) { |
| 3921 | // No change in provisioning. |
| 3922 | return; |
| 3923 | } |
| 3924 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3925 | try { |
| 3926 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3927 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3928 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3929 | + ", Exception" + e.getMessage()); |
| 3930 | } |
| 3931 | break; |
| 3932 | } |
| 3933 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3934 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3935 | + "MmTel capability '" + capability + "', which does not require " |
| 3936 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | } finally { |
| 3941 | Binder.restoreCallingIdentity(identity); |
| 3942 | } |
| 3943 | } |
| 3944 | |
| 3945 | @Override |
| 3946 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3947 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3948 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3949 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3950 | } |
| 3951 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3955 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3956 | return true; |
| 3957 | } |
| 3958 | |
| 3959 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3960 | switch (capability) { |
| 3961 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3962 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3963 | return ims.isVolteProvisionedOnDevice(); |
| 3964 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3965 | return ims.isWfcProvisionedOnDevice(); |
| 3966 | } |
| 3967 | // This should never happen, since we are checking tech above to make sure it |
| 3968 | // is either LTE or IWLAN. |
| 3969 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3970 | + "capability."); |
| 3971 | } |
| 3972 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3973 | // There is currently no difference in VT provisioning type. |
| 3974 | return ims.isVtProvisionedOnDevice(); |
| 3975 | } |
| 3976 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3977 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3978 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3979 | } |
| 3980 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3981 | throw new IllegalArgumentException( |
| 3982 | "Tried to get provisioning for MmTel capability '" + capability |
| 3983 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | } finally { |
| 3988 | Binder.restoreCallingIdentity(identity); |
| 3989 | } |
| 3990 | } |
| 3991 | |
| 3992 | @Override |
| 3993 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3994 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3995 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3996 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3997 | } |
| 3998 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3999 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4000 | return (provisionedBits & capability) > 0; |
| 4001 | } |
| 4002 | |
| 4003 | @Override |
| 4004 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4005 | boolean isProvisioned) { |
| 4006 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4007 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4008 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4009 | } |
| 4010 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4011 | "setProvisioningStatusForCapability"); |
| 4012 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4013 | // If the current provisioning status for capability already matches isProvisioned, |
| 4014 | // do nothing. |
| 4015 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4016 | return; |
| 4017 | } |
| 4018 | if (isProvisioned) { |
| 4019 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4020 | } else { |
| 4021 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4022 | } |
| 4023 | } |
| 4024 | |
| 4025 | /** |
| 4026 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4027 | * technology. The bitfield should mirror the bitfield defined by |
| 4028 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4029 | */ |
| 4030 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4031 | String key = getMmTelProvisioningKey(subId, tech); |
| 4032 | // Default is no capabilities are provisioned. |
| 4033 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4034 | } |
| 4035 | |
| 4036 | /** |
| 4037 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4038 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4039 | * technology specified. |
| 4040 | * |
| 4041 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4042 | */ |
| 4043 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4044 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4045 | String key = getMmTelProvisioningKey(subId, tech); |
| 4046 | editor.putInt(key, newField); |
| 4047 | editor.commit(); |
| 4048 | } |
| 4049 | |
| 4050 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4051 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4052 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4053 | } |
| 4054 | |
| 4055 | /** |
| 4056 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4057 | * carrier associated with the subscription id. |
| 4058 | */ |
| 4059 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4060 | int capability) { |
| 4061 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4062 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4063 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4064 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4065 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4066 | false); |
| 4067 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4068 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4069 | |
| 4070 | // First check to make sure that the capability requires provisioning. |
| 4071 | switch (capability) { |
| 4072 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4073 | // intentional fallthrough |
| 4074 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4075 | if (requireVoiceVtProvisioning) { |
| 4076 | // Voice and Video requires provisioning |
| 4077 | return true; |
| 4078 | } |
| 4079 | break; |
| 4080 | } |
| 4081 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4082 | if (requireUtProvisioning) { |
| 4083 | // UT requires provisioning |
| 4084 | return true; |
| 4085 | } |
| 4086 | break; |
| 4087 | } |
| 4088 | } |
| 4089 | return false; |
| 4090 | } |
| 4091 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4092 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4093 | int capability) { |
| 4094 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4095 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4096 | |
| 4097 | boolean requireRcsProvisioning = c.getBoolean( |
| 4098 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4099 | |
| 4100 | // First check to make sure that the capability requires provisioning. |
| 4101 | switch (capability) { |
| 4102 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4103 | // intentional fallthrough |
| 4104 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4105 | if (requireRcsProvisioning) { |
| 4106 | // OPTION or PRESENCE requires provisioning |
| 4107 | return true; |
| 4108 | } |
| 4109 | break; |
| 4110 | } |
| 4111 | } |
| 4112 | return false; |
| 4113 | } |
| 4114 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4115 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4116 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4117 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4118 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4119 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4120 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4121 | final long identity = Binder.clearCallingIdentity(); |
| 4122 | try { |
| 4123 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4124 | int slotId = getSlotIndex(subId); |
| 4125 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4126 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4127 | + subId + "' for key:" + key); |
| 4128 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4129 | } |
| 4130 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4131 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4132 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4133 | + subId + "' for key:" + key); |
| 4134 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4135 | } finally { |
| 4136 | Binder.restoreCallingIdentity(identity); |
| 4137 | } |
| 4138 | } |
| 4139 | |
| 4140 | @Override |
| 4141 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4142 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4143 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4144 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4145 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4146 | final long identity = Binder.clearCallingIdentity(); |
| 4147 | try { |
| 4148 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4149 | int slotId = getSlotIndex(subId); |
| 4150 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4151 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4152 | + subId + "' for key:" + key); |
| 4153 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4154 | } |
| 4155 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4156 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4157 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4158 | + subId + "' for key:" + key); |
| 4159 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4160 | } finally { |
| 4161 | Binder.restoreCallingIdentity(identity); |
| 4162 | } |
| 4163 | } |
| 4164 | |
| 4165 | @Override |
| 4166 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4167 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4168 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4169 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4170 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4171 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4172 | final long identity = Binder.clearCallingIdentity(); |
| 4173 | try { |
| 4174 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4175 | int slotId = getSlotIndex(subId); |
| 4176 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4177 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4178 | + subId + "' for key:" + key); |
| 4179 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4180 | } |
| 4181 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4182 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4183 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4184 | + "' for key:" + key); |
| 4185 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4186 | } finally { |
| 4187 | Binder.restoreCallingIdentity(identity); |
| 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | @Override |
| 4192 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4193 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4194 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4195 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4196 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4197 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4198 | final long identity = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4201 | int slotId = getSlotIndex(subId); |
| 4202 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4203 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4204 | + subId + "' for key:" + key); |
| 4205 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4206 | } |
| 4207 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4208 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4209 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4210 | + "' for key:" + key); |
| 4211 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4212 | } finally { |
| 4213 | Binder.restoreCallingIdentity(identity); |
| 4214 | } |
| 4215 | } |
| 4216 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4217 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4218 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4219 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4220 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4221 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4222 | } |
| 4223 | return slotId; |
| 4224 | } |
| 4225 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4226 | private int getSlotIndex(int subId) { |
| 4227 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4228 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4229 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4230 | } |
| 4231 | return slotId; |
| 4232 | } |
| 4233 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4234 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4235 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4236 | */ |
| 4237 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4238 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4239 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4240 | final int targetSdk = getTargetSdk(callingPackage); |
| 4241 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4242 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4243 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4244 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4245 | mApp, subId, callingPackage, callingFeatureId, |
| 4246 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4247 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4248 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4249 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4250 | final long identity = Binder.clearCallingIdentity(); |
| 4251 | try { |
| 4252 | final Phone phone = getPhone(subId); |
| 4253 | if (phone != null) { |
| 4254 | return phone.getServiceState().getDataNetworkType(); |
| 4255 | } else { |
| 4256 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4257 | } |
| 4258 | } finally { |
| 4259 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4260 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | /** |
| 4264 | * Returns the data network type |
| 4265 | */ |
| 4266 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4267 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4268 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4269 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | /** |
| 4273 | * Returns the data network type for a subId |
| 4274 | */ |
| 4275 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4276 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4277 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4279 | mApp, subId, callingPackage, callingFeatureId, |
| 4280 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4281 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4282 | } |
| 4283 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | final Phone phone = getPhone(subId); |
| 4287 | if (phone != null) { |
| 4288 | return phone.getServiceState().getDataNetworkType(); |
| 4289 | } else { |
| 4290 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4291 | } |
| 4292 | } finally { |
| 4293 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4294 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4298 | * Returns the Voice network type for a subId |
| 4299 | */ |
| 4300 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4301 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4302 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4303 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4304 | mApp, subId, callingPackage, callingFeatureId, |
| 4305 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4306 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4307 | } |
| 4308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
| 4311 | final Phone phone = getPhone(subId); |
| 4312 | if (phone != null) { |
| 4313 | return phone.getServiceState().getVoiceNetworkType(); |
| 4314 | } else { |
| 4315 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4316 | } |
| 4317 | } finally { |
| 4318 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4319 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | /** |
| 4323 | * @return true if a ICC card is present |
| 4324 | */ |
| 4325 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4326 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4327 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4328 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4332 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4333 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4334 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4335 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4336 | final long identity = Binder.clearCallingIdentity(); |
| 4337 | try { |
| 4338 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4339 | if (phone != null) { |
| 4340 | return phone.getIccCard().hasIccCard(); |
| 4341 | } else { |
| 4342 | return false; |
| 4343 | } |
| 4344 | } finally { |
| 4345 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4346 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4347 | } |
| 4348 | |
| 4349 | /** |
| 4350 | * Return if the current radio is LTE on CDMA. This |
| 4351 | * is a tri-state return value as for a period of time |
| 4352 | * the mode may be unknown. |
| 4353 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4354 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4355 | * @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] | 4356 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4357 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4358 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4359 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4360 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4361 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4364 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4365 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4366 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4367 | try { |
| 4368 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4369 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4370 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4371 | } |
| 4372 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4373 | final long identity = Binder.clearCallingIdentity(); |
| 4374 | try { |
| 4375 | final Phone phone = getPhone(subId); |
| 4376 | if (phone == null) { |
| 4377 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4378 | } else { |
| 4379 | return phone.getLteOnCdmaMode(); |
| 4380 | } |
| 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4383 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4386 | /** |
| 4387 | * {@hide} |
| 4388 | * Returns Default subId, 0 in the case of single standby. |
| 4389 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4390 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4391 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4392 | } |
| 4393 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4394 | private int getSlotForDefaultSubscription() { |
| 4395 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4396 | } |
| 4397 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4398 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4399 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4400 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4401 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4402 | private boolean isActiveSubscription(int subId) { |
| 4403 | return mSubscriptionController.isActiveSubId(subId); |
| 4404 | } |
| 4405 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4406 | /** |
| 4407 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4408 | */ |
| 4409 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4410 | final long identity = Binder.clearCallingIdentity(); |
| 4411 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4412 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4413 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4414 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4415 | } finally { |
| 4416 | Binder.restoreCallingIdentity(identity); |
| 4417 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | /** |
| 4421 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4422 | */ |
| 4423 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4424 | final long identity = Binder.clearCallingIdentity(); |
| 4425 | try { |
| 4426 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4427 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4428 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4429 | } finally { |
| 4430 | Binder.restoreCallingIdentity(identity); |
| 4431 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4432 | } |
| 4433 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4434 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4435 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4436 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4437 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4438 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4439 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4440 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4441 | if (phoneId == -1) { |
| 4442 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4443 | + " does not correspond to an active phone"); |
| 4444 | } |
| 4445 | return PhoneFactory.getPhone(phoneId); |
| 4446 | } |
| 4447 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4448 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4449 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4450 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4451 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4452 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4453 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4454 | if (DBG) { |
| 4455 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4456 | } |
| 4457 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4458 | p2); |
| 4459 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4460 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4461 | |
| 4462 | @Override |
| 4463 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4464 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4465 | enforceModifyPermission(); |
| 4466 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4467 | if (DBG) { |
| 4468 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4469 | } |
| 4470 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4471 | callingPackage, aid, p2); |
| 4472 | } |
| 4473 | |
| 4474 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4475 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | final long identity = Binder.clearCallingIdentity(); |
| 4477 | try { |
| 4478 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4479 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4480 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4481 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | if (bestComponent == null |
| 4483 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4484 | loge("The calling package is not allowed to access ISD-R."); |
| 4485 | throw new SecurityException( |
| 4486 | "The calling package is not allowed to access ISD-R."); |
| 4487 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4488 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4489 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4490 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4491 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4492 | null /* workSource */); |
| 4493 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4494 | return response; |
| 4495 | } finally { |
| 4496 | Binder.restoreCallingIdentity(identity); |
| 4497 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
| 4500 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4501 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4503 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4504 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4505 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4506 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4507 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4508 | @Override |
| 4509 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4510 | enforceModifyPermission(); |
| 4511 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4512 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4513 | channel); |
| 4514 | } |
| 4515 | |
| 4516 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4517 | final long identity = Binder.clearCallingIdentity(); |
| 4518 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4519 | if (channel < 0) { |
| 4520 | return false; |
| 4521 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4522 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4523 | null /* workSource */); |
| 4524 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | return success; |
| 4526 | } finally { |
| 4527 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4528 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4532 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4533 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4535 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4536 | if (DBG) { |
| 4537 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4538 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4539 | + p3 + " data=" + data); |
| 4540 | } |
| 4541 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4542 | command, p1, p2, p3, data); |
| 4543 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4544 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4545 | @Override |
| 4546 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4547 | int command, int p1, int p2, int p3, String data) { |
| 4548 | enforceModifyPermission(); |
| 4549 | if (DBG) { |
| 4550 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4551 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4552 | + p3 + " data=" + data); |
| 4553 | } |
| 4554 | return iccTransmitApduLogicalChannelWithPermission( |
| 4555 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4556 | data); |
| 4557 | } |
| 4558 | |
| 4559 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4560 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4561 | final long identity = Binder.clearCallingIdentity(); |
| 4562 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4563 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4564 | return ""; |
| 4565 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4566 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4567 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4568 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4569 | null /* workSource */); |
| 4570 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4571 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4572 | // Append the returned status code to the end of the response payload. |
| 4573 | String s = Integer.toHexString( |
| 4574 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4575 | if (response.payload != null) { |
| 4576 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4577 | } |
| 4578 | return s; |
| 4579 | } finally { |
| 4580 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4581 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4582 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4583 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4584 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4585 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4586 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4588 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4589 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4590 | if (DBG) { |
| 4591 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4592 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4593 | } |
| 4594 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4595 | cla, command, p1, p2, p3, data); |
| 4596 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4597 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4598 | @Override |
| 4599 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4600 | int command, int p1, int p2, int p3, String data) { |
| 4601 | enforceModifyPermission(); |
| 4602 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4603 | if (DBG) { |
| 4604 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4605 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4606 | + " data=" + data); |
| 4607 | } |
| 4608 | |
| 4609 | return iccTransmitApduBasicChannelWithPermission( |
| 4610 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4611 | p2, p3, data); |
| 4612 | } |
| 4613 | |
| 4614 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4615 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4616 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4617 | final long identity = Binder.clearCallingIdentity(); |
| 4618 | try { |
| 4619 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4620 | && TextUtils.equals(ISDR_AID, data)) { |
| 4621 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4622 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4623 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4624 | if (bestComponent == null |
| 4625 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4626 | loge("The calling package is not allowed to select ISD-R."); |
| 4627 | throw new SecurityException( |
| 4628 | "The calling package is not allowed to select ISD-R."); |
| 4629 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4630 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4631 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4632 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4633 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4634 | null /* workSource */); |
| 4635 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4636 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4637 | // Append the returned status code to the end of the response payload. |
| 4638 | String s = Integer.toHexString( |
| 4639 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4640 | if (response.payload != null) { |
| 4641 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4642 | } |
| 4643 | return s; |
| 4644 | } finally { |
| 4645 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4646 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4650 | 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] | 4651 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4652 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4653 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4654 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4655 | final long identity = Binder.clearCallingIdentity(); |
| 4656 | try { |
| 4657 | if (DBG) { |
| 4658 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4659 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4660 | } |
| 4661 | |
| 4662 | IccIoResult response = |
| 4663 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4664 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4665 | subId); |
| 4666 | |
| 4667 | if (DBG) { |
| 4668 | log("Exchange SIM_IO [R]" + response); |
| 4669 | } |
| 4670 | |
| 4671 | byte[] result = null; |
| 4672 | int length = 2; |
| 4673 | if (response.payload != null) { |
| 4674 | length = 2 + response.payload.length; |
| 4675 | result = new byte[length]; |
| 4676 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4677 | } else { |
| 4678 | result = new byte[length]; |
| 4679 | } |
| 4680 | |
| 4681 | result[length - 1] = (byte) response.sw2; |
| 4682 | result[length - 2] = (byte) response.sw1; |
| 4683 | return result; |
| 4684 | } finally { |
| 4685 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4686 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4687 | } |
| 4688 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4689 | /** |
| 4690 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4691 | * on a particular subscription |
| 4692 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4693 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4694 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4695 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4696 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4697 | return null; |
| 4698 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4699 | |
| 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
| 4702 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4703 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4704 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4705 | return null; |
| 4706 | } |
| 4707 | Object response = sendRequest( |
| 4708 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4709 | if (response instanceof String[]) { |
| 4710 | return (String[]) response; |
| 4711 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4712 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4713 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4714 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4715 | } finally { |
| 4716 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4717 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4718 | } |
| 4719 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4720 | /** |
| 4721 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4722 | * subscription. |
| 4723 | * |
| 4724 | * @param subId the id of the subscription. |
| 4725 | * @param appType the uicc app type, must be USIM or SIM. |
| 4726 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4727 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4728 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4729 | * @return number of fplmns that is successfully written to the SIM. |
| 4730 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4731 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4732 | String callingFeatureId) { |
| 4733 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4734 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4735 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4736 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4737 | } |
| 4738 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4739 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4740 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4741 | } |
| 4742 | if (fplmns == null) { |
| 4743 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4744 | } |
| 4745 | for (String fplmn : fplmns) { |
| 4746 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4747 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4748 | } |
| 4749 | } |
| 4750 | final long identity = Binder.clearCallingIdentity(); |
| 4751 | try { |
| 4752 | Object response = sendRequest( |
| 4753 | CMD_SET_FORBIDDEN_PLMNS, |
| 4754 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4755 | subId); |
| 4756 | return (int) response; |
| 4757 | } finally { |
| 4758 | Binder.restoreCallingIdentity(identity); |
| 4759 | } |
| 4760 | } |
| 4761 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4762 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4763 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4764 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4765 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4767 | final long identity = Binder.clearCallingIdentity(); |
| 4768 | try { |
| 4769 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4770 | if (response.payload == null) { |
| 4771 | return ""; |
| 4772 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4773 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4774 | // Append the returned status code to the end of the response payload. |
| 4775 | String s = Integer.toHexString( |
| 4776 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4777 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4778 | return s; |
| 4779 | } finally { |
| 4780 | Binder.restoreCallingIdentity(identity); |
| 4781 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4782 | } |
| 4783 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4784 | /** |
| 4785 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4786 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4787 | * |
| 4788 | * @param itemID the ID of the item to read |
| 4789 | * @return the NV item as a String, or null on error. |
| 4790 | */ |
| 4791 | @Override |
| 4792 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4793 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4794 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4795 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4796 | |
| 4797 | final long identity = Binder.clearCallingIdentity(); |
| 4798 | try { |
| 4799 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4800 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4801 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4802 | return value; |
| 4803 | } finally { |
| 4804 | Binder.restoreCallingIdentity(identity); |
| 4805 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | /** |
| 4809 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4810 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4811 | * |
| 4812 | * @param itemID the ID of the item to read |
| 4813 | * @param itemValue the value to write, as a String |
| 4814 | * @return true on success; false on any failure |
| 4815 | */ |
| 4816 | @Override |
| 4817 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4818 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4819 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4820 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4821 | |
| 4822 | final long identity = Binder.clearCallingIdentity(); |
| 4823 | try { |
| 4824 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4825 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4826 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4827 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4828 | return success; |
| 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
| 4831 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | /** |
| 4835 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4836 | * Used for device configuration by some CDMA operators. |
| 4837 | * |
| 4838 | * @param preferredRoamingList byte array containing the new PRL |
| 4839 | * @return true on success; false on any failure |
| 4840 | */ |
| 4841 | @Override |
| 4842 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4844 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4845 | |
| 4846 | final long identity = Binder.clearCallingIdentity(); |
| 4847 | try { |
| 4848 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4849 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4850 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4851 | return success; |
| 4852 | } finally { |
| 4853 | Binder.restoreCallingIdentity(identity); |
| 4854 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4858 | * 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] | 4859 | * Used for device configuration by some CDMA operators. |
| 4860 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4861 | * @param slotIndex - device slot. |
| 4862 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4863 | * @return true on success; false on any failure |
| 4864 | */ |
| 4865 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4866 | public boolean resetModemConfig(int slotIndex) { |
| 4867 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4868 | if (phone != null) { |
| 4869 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4870 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4871 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4872 | final long identity = Binder.clearCallingIdentity(); |
| 4873 | try { |
| 4874 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4875 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4876 | return success; |
| 4877 | } finally { |
| 4878 | Binder.restoreCallingIdentity(identity); |
| 4879 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4880 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4881 | return false; |
| 4882 | } |
| 4883 | |
| 4884 | /** |
| 4885 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4886 | * |
| 4887 | * @param slotIndex - device slot. |
| 4888 | * |
| 4889 | * @return true on success; false on any failure |
| 4890 | */ |
| 4891 | @Override |
| 4892 | public boolean rebootModem(int slotIndex) { |
| 4893 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4894 | if (phone != null) { |
| 4895 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4896 | mApp, phone.getSubId(), "rebootModem"); |
| 4897 | |
| 4898 | final long identity = Binder.clearCallingIdentity(); |
| 4899 | try { |
| 4900 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4901 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4902 | return success; |
| 4903 | } finally { |
| 4904 | Binder.restoreCallingIdentity(identity); |
| 4905 | } |
| 4906 | } |
| 4907 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4908 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4909 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4910 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4911 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4912 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4913 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4914 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4915 | return new String[0]; |
| 4916 | } |
| 4917 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4918 | final long identity = Binder.clearCallingIdentity(); |
| 4919 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4920 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4921 | } finally { |
| 4922 | Binder.restoreCallingIdentity(identity); |
| 4923 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4926 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4927 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4928 | * {@link #disableIms(int)}. |
| 4929 | * @param slotIndex device slot. |
| 4930 | */ |
| 4931 | public void resetIms(int slotIndex) { |
| 4932 | enforceModifyPermission(); |
| 4933 | |
| 4934 | final long identity = Binder.clearCallingIdentity(); |
| 4935 | try { |
| 4936 | if (mImsResolver == null) { |
| 4937 | // may happen if the does not support IMS. |
| 4938 | return; |
| 4939 | } |
| 4940 | mImsResolver.disableIms(slotIndex); |
| 4941 | mImsResolver.enableIms(slotIndex); |
| 4942 | } finally { |
| 4943 | Binder.restoreCallingIdentity(identity); |
| 4944 | } |
| 4945 | } |
| 4946 | |
| 4947 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4948 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4949 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4950 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4951 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4952 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4953 | |
| 4954 | final long identity = Binder.clearCallingIdentity(); |
| 4955 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4956 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4957 | // may happen if the device does not support IMS. |
| 4958 | return; |
| 4959 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4960 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4961 | } finally { |
| 4962 | Binder.restoreCallingIdentity(identity); |
| 4963 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4967 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4968 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4969 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4970 | public void disableIms(int slotId) { |
| 4971 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | |
| 4973 | final long identity = Binder.clearCallingIdentity(); |
| 4974 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4975 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4976 | // may happen if the device does not support IMS. |
| 4977 | return; |
| 4978 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4979 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4980 | } finally { |
| 4981 | Binder.restoreCallingIdentity(identity); |
| 4982 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | /** |
| 4986 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4987 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4988 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4989 | */ |
| 4990 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4991 | IImsServiceFeatureCallback callback) { |
| 4992 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | |
| 4994 | final long identity = Binder.clearCallingIdentity(); |
| 4995 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4996 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4997 | // may happen if the device does not support IMS. |
| 4998 | return null; |
| 4999 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5000 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | } finally { |
| 5002 | Binder.restoreCallingIdentity(identity); |
| 5003 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | /** |
| 5007 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 5008 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 5009 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 5010 | * listener for feature updates. |
| 5011 | */ |
| 5012 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 5013 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5014 | |
| 5015 | final long identity = Binder.clearCallingIdentity(); |
| 5016 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5017 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5018 | // may happen if the device does not support IMS. |
| 5019 | return null; |
| 5020 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5021 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | } finally { |
| 5023 | Binder.restoreCallingIdentity(identity); |
| 5024 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5025 | } |
| 5026 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5027 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5028 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5029 | */ |
| 5030 | public void unregisterImsFeatureCallback(int slotId, int featureType, |
| 5031 | IImsServiceFeatureCallback callback) { |
| 5032 | enforceModifyPermission(); |
| 5033 | |
| 5034 | final long identity = Binder.clearCallingIdentity(); |
| 5035 | try { |
| 5036 | if (mImsResolver == null) return; |
| 5037 | mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback); |
| 5038 | } finally { |
| 5039 | Binder.restoreCallingIdentity(identity); |
| 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5044 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5045 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5046 | */ |
| 5047 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5048 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5049 | |
| 5050 | final long identity = Binder.clearCallingIdentity(); |
| 5051 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5052 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5053 | // may happen if the device does not support IMS. |
| 5054 | return null; |
| 5055 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5056 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5057 | } finally { |
| 5058 | Binder.restoreCallingIdentity(identity); |
| 5059 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5060 | } |
| 5061 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5062 | /** |
| 5063 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5064 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5065 | */ |
| 5066 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5067 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5068 | |
| 5069 | final long identity = Binder.clearCallingIdentity(); |
| 5070 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5071 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5072 | // may happen if the device does not support IMS. |
| 5073 | return null; |
| 5074 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5075 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5076 | } finally { |
| 5077 | Binder.restoreCallingIdentity(identity); |
| 5078 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5079 | } |
| 5080 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5081 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5082 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5083 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5084 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5085 | * @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] | 5086 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5087 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5088 | * @param packageName The name of the package that the current configuration will be replaced |
| 5089 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5090 | * @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] | 5091 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5092 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5093 | int[] featureTypes, String packageName) { |
| 5094 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5095 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5096 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5097 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5098 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5099 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5100 | final long identity = Binder.clearCallingIdentity(); |
| 5101 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5102 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5103 | // may happen if the device does not support IMS. |
| 5104 | return false; |
| 5105 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5106 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5107 | for (int featureType : featureTypes) { |
| 5108 | featureConfig.put(featureType, packageName); |
| 5109 | } |
| 5110 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5111 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5112 | } finally { |
| 5113 | Binder.restoreCallingIdentity(identity); |
| 5114 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5118 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5119 | * |
| 5120 | * @param slotId The slot that the ImsService is associated with. |
| 5121 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5122 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5123 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5124 | * @return the package name of the ImsService configuration. |
| 5125 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5126 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5127 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5128 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5129 | TelephonyPermissions |
| 5130 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5131 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5132 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5133 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5134 | final long identity = Binder.clearCallingIdentity(); |
| 5135 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5136 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5137 | // may happen if the device does not support IMS. |
| 5138 | return ""; |
| 5139 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5140 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5141 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5142 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5143 | } finally { |
| 5144 | Binder.restoreCallingIdentity(identity); |
| 5145 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5148 | /** |
| 5149 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5150 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5151 | * @param callback A callback with an integer containing the |
| 5152 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5153 | */ |
| 5154 | @Override |
| 5155 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5156 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5157 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5158 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5159 | "IMS not available on device."); |
| 5160 | } |
| 5161 | final long token = Binder.clearCallingIdentity(); |
| 5162 | try { |
| 5163 | int slotId = getSlotIndex(subId); |
| 5164 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5165 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5166 | + subId + "'"); |
| 5167 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5168 | } |
| 5169 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5170 | try { |
| 5171 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5172 | } catch (RemoteException e) { |
| 5173 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5174 | + "Ignore"); |
| 5175 | } |
| 5176 | }); |
| 5177 | } finally { |
| 5178 | Binder.restoreCallingIdentity(token); |
| 5179 | } |
| 5180 | } |
| 5181 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5182 | public void setImsRegistrationState(boolean registered) { |
| 5183 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5184 | |
| 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5187 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5188 | } finally { |
| 5189 | Binder.restoreCallingIdentity(identity); |
| 5190 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
| 5193 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5194 | * Set the network selection mode to automatic. |
| 5195 | * |
| 5196 | */ |
| 5197 | @Override |
| 5198 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5199 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5200 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5201 | |
| 5202 | final long identity = Binder.clearCallingIdentity(); |
| 5203 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5204 | if (!isActiveSubscription(subId)) { |
| 5205 | return; |
| 5206 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5208 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5209 | } finally { |
| 5210 | Binder.restoreCallingIdentity(identity); |
| 5211 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5212 | } |
| 5213 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5214 | /** |
| 5215 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5216 | * |
| 5217 | * @param subId the id of the subscription. |
| 5218 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5219 | * the operator to attach to. |
| 5220 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5221 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5222 | * normal network selection next time. |
| 5223 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5224 | */ |
| 5225 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5226 | public boolean setNetworkSelectionModeManual( |
| 5227 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5229 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5230 | |
| 5231 | if (!isActiveSubscription(subId)) { |
| 5232 | return false; |
| 5233 | } |
| 5234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5235 | final long identity = Binder.clearCallingIdentity(); |
| 5236 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5237 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5239 | if (DBG) { |
| 5240 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5241 | + " operator: " + operatorInfo); |
| 5242 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5243 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
| 5246 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5247 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5248 | /** |
| 5249 | * Get the manual network selection |
| 5250 | * |
| 5251 | * @param subId the id of the subscription. |
| 5252 | * |
| 5253 | * @return the previously saved user selected PLMN |
| 5254 | */ |
| 5255 | @Override |
| 5256 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5257 | TelephonyPermissions |
| 5258 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5259 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5260 | |
| 5261 | final long identity = Binder.clearCallingIdentity(); |
| 5262 | try { |
| 5263 | if (!isActiveSubscription(subId)) { |
| 5264 | return ""; |
| 5265 | } |
| 5266 | |
| 5267 | final Phone phone = getPhone(subId); |
| 5268 | if (phone == null) { |
| 5269 | return ""; |
| 5270 | } |
| 5271 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5272 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5273 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5274 | } finally { |
| 5275 | Binder.restoreCallingIdentity(identity); |
| 5276 | } |
| 5277 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5278 | |
| 5279 | /** |
| 5280 | * Scans for available networks. |
| 5281 | */ |
| 5282 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5283 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5284 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5285 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5286 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5287 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5288 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5289 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5290 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5291 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5292 | .setCallingPid(Binder.getCallingPid()) |
| 5293 | .setCallingUid(Binder.getCallingUid()) |
| 5294 | .setMethod("getCellNetworkScanResults") |
| 5295 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5296 | .build()); |
| 5297 | switch (locationResult) { |
| 5298 | case DENIED_HARD: |
| 5299 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5300 | case DENIED_SOFT: |
| 5301 | return null; |
| 5302 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5304 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5305 | try { |
| 5306 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5307 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5308 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
| 5311 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5315 | * Get the call forwarding info, given the call forwarding reason. |
| 5316 | */ |
| 5317 | @Override |
| 5318 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5319 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5320 | long identity = Binder.clearCallingIdentity(); |
| 5321 | try { |
| 5322 | if (DBG) { |
| 5323 | log("getCallForwarding: subId " + subId |
| 5324 | + " callForwardingReason" + callForwardingReason); |
| 5325 | } |
| 5326 | return (CallForwardingInfo) sendRequest( |
| 5327 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(identity); |
| 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | /** |
| 5334 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5335 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5336 | */ |
| 5337 | @Override |
| 5338 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5339 | enforceModifyPermission(); |
| 5340 | long identity = Binder.clearCallingIdentity(); |
| 5341 | try { |
| 5342 | if (DBG) { |
| 5343 | log("setCallForwarding: subId " + subId |
| 5344 | + " callForwardingInfo" + callForwardingInfo); |
| 5345 | } |
| 5346 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5347 | } finally { |
| 5348 | Binder.restoreCallingIdentity(identity); |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | /** |
| 5353 | * Get the call forwarding info, given the call forwarding reason. |
| 5354 | */ |
| 5355 | @Override |
| 5356 | public int getCallWaitingStatus(int subId) { |
| 5357 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5358 | long identity = Binder.clearCallingIdentity(); |
| 5359 | try { |
| 5360 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5361 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5362 | } finally { |
| 5363 | Binder.restoreCallingIdentity(identity); |
| 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | /** |
| 5368 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5369 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5370 | */ |
| 5371 | @Override |
| 5372 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5373 | enforceModifyPermission(); |
| 5374 | long identity = Binder.clearCallingIdentity(); |
| 5375 | try { |
| 5376 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5377 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5378 | } finally { |
| 5379 | Binder.restoreCallingIdentity(identity); |
| 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5384 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5385 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5386 | * @param subId id of the subscription |
| 5387 | * @param request contains the radio access networks with bands/channels to scan |
| 5388 | * @param messenger callback messenger for scan results or errors |
| 5389 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5390 | * @return the id of the requested scan which can be used to stop the scan. |
| 5391 | */ |
| 5392 | @Override |
| 5393 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5394 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5395 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5396 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5397 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5398 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5399 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5400 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5401 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5402 | .setCallingPid(Binder.getCallingPid()) |
| 5403 | .setCallingUid(Binder.getCallingUid()) |
| 5404 | .setMethod("requestNetworkScan") |
| 5405 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5406 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5407 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5408 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5409 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5410 | if (e != null) { |
| 5411 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5412 | throw e; |
| 5413 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5414 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5415 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5416 | } |
| 5417 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5419 | int callingUid = Binder.getCallingUid(); |
| 5420 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5421 | final long identity = Binder.clearCallingIdentity(); |
| 5422 | try { |
| 5423 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5424 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5425 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5426 | } finally { |
| 5427 | Binder.restoreCallingIdentity(identity); |
| 5428 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5431 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5432 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5433 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5434 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5435 | boolean hasNetworkScanPermission = |
| 5436 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5437 | == PERMISSION_GRANTED; |
| 5438 | |
| 5439 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5440 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5441 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5445 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5446 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5447 | return new SecurityException("Specific channels must not be" |
| 5448 | + " scanned without location access."); |
| 5449 | } |
| 5450 | } |
| 5451 | } |
| 5452 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5453 | return null; |
| 5454 | } |
| 5455 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5456 | /** |
| 5457 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5458 | * |
| 5459 | * @param subId id of the subscription |
| 5460 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5461 | */ |
| 5462 | @Override |
| 5463 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5464 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5465 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5466 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5467 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | final long identity = Binder.clearCallingIdentity(); |
| 5469 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5470 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | } finally { |
| 5472 | Binder.restoreCallingIdentity(identity); |
| 5473 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5477 | * Get the calculated preferred network type. |
| 5478 | * Used for debugging incorrect network type. |
| 5479 | * |
| 5480 | * @return the preferred network type, defined in RILConstants.java. |
| 5481 | */ |
| 5482 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5483 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5484 | final Phone defaultPhone = getDefaultPhone(); |
| 5485 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5486 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5487 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5488 | } |
| 5489 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5490 | final long identity = Binder.clearCallingIdentity(); |
| 5491 | try { |
| 5492 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5493 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | } finally { |
| 5495 | Binder.restoreCallingIdentity(identity); |
| 5496 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5500 | * Get the preferred network type. |
| 5501 | * Used for device configuration by some CDMA operators. |
| 5502 | * |
| 5503 | * @return the preferred network type, defined in RILConstants.java. |
| 5504 | */ |
| 5505 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5506 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5507 | TelephonyPermissions |
| 5508 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5509 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5510 | |
| 5511 | final long identity = Binder.clearCallingIdentity(); |
| 5512 | try { |
| 5513 | if (DBG) log("getPreferredNetworkType"); |
| 5514 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5515 | int networkType = (result != null ? result[0] : -1); |
| 5516 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5517 | return networkType; |
| 5518 | } finally { |
| 5519 | Binder.restoreCallingIdentity(identity); |
| 5520 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | /** |
| 5524 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5525 | * |
| 5526 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5527 | * @return true on success; false on any failure. |
| 5528 | */ |
| 5529 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5530 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5531 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5532 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | |
| 5534 | final long identity = Binder.clearCallingIdentity(); |
| 5535 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5536 | Boolean success = (Boolean) sendRequest( |
| 5537 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5538 | |
| 5539 | if (success) { |
| 5540 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5541 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5542 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5543 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5544 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5545 | } finally { |
| 5546 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5547 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5548 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5549 | |
| 5550 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5551 | * Get the allowed network types that store in the telephony provider. |
| 5552 | * |
| 5553 | * @param subId the id of the subscription. |
| 5554 | * @return allowedNetworkTypes the allowed network types. |
| 5555 | */ |
| 5556 | @Override |
| 5557 | public long getAllowedNetworkTypes(int subId) { |
| 5558 | TelephonyPermissions |
| 5559 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5560 | mApp, subId, "getAllowedNetworkTypes"); |
| 5561 | |
| 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
| 5564 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5565 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5566 | } finally { |
| 5567 | Binder.restoreCallingIdentity(identity); |
| 5568 | } |
| 5569 | } |
| 5570 | |
| 5571 | /** |
| 5572 | * Set the allowed network types. |
| 5573 | * |
| 5574 | * @param subId the id of the subscription. |
| 5575 | * @param allowedNetworkTypes the allowed network types. |
| 5576 | * @return true on success; false on any failure. |
| 5577 | */ |
| 5578 | @Override |
| 5579 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5581 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5582 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5583 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5584 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5585 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5586 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5587 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5588 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5589 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5590 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5591 | } |
| 5592 | |
| 5593 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5594 | * Get the allowed network types for certain reason. |
| 5595 | * |
| 5596 | * @param subId the id of the subscription. |
| 5597 | * @param reason the reason the allowed network type change is taking place |
| 5598 | * @return the allowed network types. |
| 5599 | */ |
| 5600 | @Override |
| 5601 | public long getAllowedNetworkTypesForReason(int subId, |
| 5602 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5603 | TelephonyPermissions |
| 5604 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5605 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5606 | final long identity = Binder.clearCallingIdentity(); |
| 5607 | try { |
| 5608 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5609 | } finally { |
| 5610 | Binder.restoreCallingIdentity(identity); |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | /** |
| 5615 | * Get the effective allowed network types on the device. |
| 5616 | * This API will return an intersection of allowed network types for all reasons, |
| 5617 | * including the configuration done through setAllowedNetworkTypes |
| 5618 | * |
| 5619 | * @param subId the id of the subscription. |
| 5620 | * @return the allowed network types |
| 5621 | */ |
| 5622 | @Override |
| 5623 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5624 | TelephonyPermissions |
| 5625 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5626 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5627 | final long identity = Binder.clearCallingIdentity(); |
| 5628 | try { |
| 5629 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5630 | } finally { |
| 5631 | Binder.restoreCallingIdentity(identity); |
| 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | /** |
| 5636 | * Set the allowed network types of the device and |
| 5637 | * provide the reason triggering the allowed network change. |
| 5638 | * |
| 5639 | * @param subId the id of the subscription. |
| 5640 | * @param reason the reason the allowed network type change is taking place |
| 5641 | * @param allowedNetworkTypes the allowed network types. |
| 5642 | * @return true on success; false on any failure. |
| 5643 | */ |
| 5644 | @Override |
| 5645 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 5646 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 5647 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5648 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 5649 | final long identity = Binder.clearCallingIdentity(); |
| 5650 | try { |
| 5651 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 5652 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5653 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5654 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5655 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 5656 | } finally { |
| 5657 | Binder.restoreCallingIdentity(identity); |
| 5658 | } |
| 5659 | } |
| 5660 | |
| 5661 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5662 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5663 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5664 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5665 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5666 | * @hide |
| 5667 | */ |
| 5668 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5669 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5670 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5671 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5672 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5673 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5674 | if (phone != null) { |
| 5675 | return phone.hasMatchedTetherApnSetting(); |
| 5676 | } else { |
| 5677 | return false; |
| 5678 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5679 | } finally { |
| 5680 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5681 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5685 | * Set mobile data enabled |
| 5686 | * Used by the user through settings etc to turn on/off mobile data |
| 5687 | * |
| 5688 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5689 | */ |
| 5690 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5691 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5692 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5693 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | |
| 5695 | final long identity = Binder.clearCallingIdentity(); |
| 5696 | try { |
| 5697 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5698 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5699 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5700 | if (phone != null) { |
| 5701 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5702 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5703 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5704 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | } |
| 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5708 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5712 | * Enable or disable always reporting signal strength changes from radio. |
| 5713 | * |
| 5714 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5715 | */ |
| 5716 | @Override |
| 5717 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5718 | enforceModifyPermission(); |
| 5719 | enforceSystemCaller(); |
| 5720 | |
| 5721 | final long identity = Binder.clearCallingIdentity(); |
| 5722 | final Phone phone = getPhone(subId); |
| 5723 | try { |
| 5724 | if (phone != null) { |
| 5725 | if (DBG) { |
| 5726 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5727 | + " isEnable=" + isEnable); |
| 5728 | } |
| 5729 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5730 | } else { |
| 5731 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5732 | + subId); |
| 5733 | } |
| 5734 | } finally { |
| 5735 | Binder.restoreCallingIdentity(identity); |
| 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5740 | * Get the user enabled state of Mobile Data. |
| 5741 | * |
| 5742 | * TODO: remove and use isUserDataEnabled. |
| 5743 | * This can't be removed now because some vendor codes |
| 5744 | * calls through ITelephony directly while they should |
| 5745 | * use TelephonyManager. |
| 5746 | * |
| 5747 | * @return true on enabled |
| 5748 | */ |
| 5749 | @Override |
| 5750 | public boolean getDataEnabled(int subId) { |
| 5751 | return isUserDataEnabled(subId); |
| 5752 | } |
| 5753 | |
| 5754 | /** |
| 5755 | * Get whether mobile data is enabled per user setting. |
| 5756 | * |
| 5757 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5758 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5759 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5760 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5761 | * |
| 5762 | * @return {@code true} if data is enabled else {@code false} |
| 5763 | */ |
| 5764 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5765 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5766 | try { |
| 5767 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5768 | null); |
| 5769 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5771 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5772 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5773 | |
| 5774 | final long identity = Binder.clearCallingIdentity(); |
| 5775 | try { |
| 5776 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5777 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5778 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5779 | if (phone != null) { |
| 5780 | boolean retVal = phone.isUserDataEnabled(); |
| 5781 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5782 | return retVal; |
| 5783 | } else { |
| 5784 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5785 | return false; |
| 5786 | } |
| 5787 | } finally { |
| 5788 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5789 | } |
| 5790 | } |
| 5791 | |
| 5792 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5793 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5794 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5795 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5796 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5797 | * @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] | 5798 | */ |
| 5799 | @Override |
| 5800 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5801 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5802 | |
| 5803 | final long identity = Binder.clearCallingIdentity(); |
| 5804 | try { |
| 5805 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5806 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5807 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5808 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5809 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5810 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5811 | return retVal; |
| 5812 | } else { |
| 5813 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5814 | return false; |
| 5815 | } |
| 5816 | } finally { |
| 5817 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5818 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5819 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5820 | |
Malcolm Chen | 6a13f2a | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5821 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5822 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 5823 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 5824 | // Skip the check if it's one of these special uids |
| 5825 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5826 | } |
| 5827 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5828 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5829 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5830 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5831 | || subController == null) return privilegeFromSim; |
| 5832 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5833 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5834 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5835 | |
| 5836 | final long identity = Binder.clearCallingIdentity(); |
| 5837 | try { |
| 5838 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5839 | SubscriptionManager subManager = (SubscriptionManager) |
| 5840 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5841 | for (String pkg : packages) { |
| 5842 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5843 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5844 | } |
| 5845 | } |
| 5846 | return privilegeFromSim; |
| 5847 | } finally { |
| 5848 | Binder.restoreCallingIdentity(identity); |
| 5849 | } |
| 5850 | } |
| 5851 | |
| 5852 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5853 | String pkgName) { |
| 5854 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5855 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5856 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5857 | || subController == null) return privilegeFromSim; |
| 5858 | |
| 5859 | final long identity = Binder.clearCallingIdentity(); |
| 5860 | try { |
| 5861 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5862 | SubscriptionManager subManager = (SubscriptionManager) |
| 5863 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5864 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5865 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5866 | } finally { |
| 5867 | Binder.restoreCallingIdentity(identity); |
| 5868 | } |
| 5869 | } |
| 5870 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5871 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5872 | public int getCarrierPrivilegeStatus(int subId) { |
| 5873 | final Phone phone = getPhone(subId); |
| 5874 | if (phone == null) { |
| 5875 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5876 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5877 | } |
| 5878 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5879 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5880 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5881 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5882 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5883 | |
| 5884 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5885 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | 6a13f2a | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5886 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5887 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5888 | |
| 5889 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5890 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5891 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5892 | final Phone phone = getPhone(subId); |
| 5893 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5894 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5895 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5896 | } |
| 5897 | UiccProfile profile = |
| 5898 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5899 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5900 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5901 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5902 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5903 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5904 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | 6a13f2a | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5905 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5909 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5910 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5911 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5915 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5916 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5917 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5918 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5919 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5920 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5921 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5922 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
| 5925 | @Override |
| 5926 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5927 | if (TextUtils.isEmpty(pkgName)) |
| 5928 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5929 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5930 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5931 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5932 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5933 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5934 | continue; |
| 5935 | } |
| 5936 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5937 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5938 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5939 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5940 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5941 | break; |
| 5942 | } |
| 5943 | } |
| 5944 | |
| 5945 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5946 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5947 | |
| 5948 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5949 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5950 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5951 | loge("phoneId " + phoneId + " is not valid."); |
| 5952 | return null; |
| 5953 | } |
| 5954 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5955 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5956 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5957 | return null ; |
| 5958 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5959 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5960 | } |
| 5961 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5962 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5963 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5964 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5965 | List<String> privilegedPackages = new ArrayList<>(); |
| 5966 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5967 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5968 | // has UICC in that slot. |
| 5969 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5970 | if (card.hasCarrierPrivilegeRules()) { |
| 5971 | if (packages == null) { |
| 5972 | // Only check packages in user 0 for now |
| 5973 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5974 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5975 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5976 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5977 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5978 | } |
| 5979 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5980 | PackageInfo pkgInfo = packages.get(p); |
| 5981 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5982 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5983 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5984 | privilegedPackages.add(pkgInfo.packageName); |
| 5985 | } |
| 5986 | } |
| 5987 | } |
| 5988 | } |
| 5989 | return privilegedPackages; |
| 5990 | } |
| 5991 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5992 | @Override |
| 5993 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5994 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5995 | |
| 5996 | final long identity = Binder.clearCallingIdentity(); |
| 5997 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5998 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5999 | try { |
| 6000 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6001 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6002 | } |
| 6003 | } finally { |
| 6004 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6005 | } |
| 6006 | return privilegedPackages; |
| 6007 | } |
| 6008 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6009 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6010 | final Phone phone = getPhone(subId); |
| 6011 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6012 | if (card == null) { |
| 6013 | loge("getIccId: No UICC"); |
| 6014 | return null; |
| 6015 | } |
| 6016 | String iccId = card.getIccId(); |
| 6017 | if (TextUtils.isEmpty(iccId)) { |
| 6018 | loge("getIccId: ICC ID is null or empty."); |
| 6019 | return null; |
| 6020 | } |
| 6021 | return iccId; |
| 6022 | } |
| 6023 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6024 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6025 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6026 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6027 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6028 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6029 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6030 | final long identity = Binder.clearCallingIdentity(); |
| 6031 | try { |
| 6032 | final String iccId = getIccId(subId); |
| 6033 | final Phone phone = getPhone(subId); |
| 6034 | if (phone == null) { |
| 6035 | return false; |
| 6036 | } |
| 6037 | final String subscriberId = phone.getSubscriberId(); |
| 6038 | |
| 6039 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6040 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | + subscriberId + " to " + number); |
| 6042 | } |
| 6043 | |
| 6044 | if (TextUtils.isEmpty(iccId)) { |
| 6045 | return false; |
| 6046 | } |
| 6047 | |
| 6048 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6049 | |
| 6050 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6051 | if (alphaTag == null) { |
| 6052 | editor.remove(alphaTagPrefKey); |
| 6053 | } else { |
| 6054 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6055 | } |
| 6056 | |
| 6057 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6058 | // track all merged IMSIs based on line number |
| 6059 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6060 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6061 | if (number == null) { |
| 6062 | editor.remove(numberPrefKey); |
| 6063 | editor.remove(subscriberPrefKey); |
| 6064 | } else { |
| 6065 | editor.putString(numberPrefKey, number); |
| 6066 | editor.putString(subscriberPrefKey, subscriberId); |
| 6067 | } |
| 6068 | |
| 6069 | editor.commit(); |
| 6070 | return true; |
| 6071 | } finally { |
| 6072 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6073 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6077 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6078 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6079 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6080 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6081 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6082 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6083 | return null; |
| 6084 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6085 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6086 | final long identity = Binder.clearCallingIdentity(); |
| 6087 | try { |
| 6088 | String iccId = getIccId(subId); |
| 6089 | if (iccId != null) { |
| 6090 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6091 | if (DBG_MERGE) { |
| 6092 | log("getLine1NumberForDisplay returning " |
| 6093 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6094 | } |
| 6095 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6096 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6097 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6098 | return null; |
| 6099 | } finally { |
| 6100 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6101 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6102 | } |
| 6103 | |
| 6104 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6105 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6106 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6107 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6108 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6109 | return null; |
| 6110 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6111 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6112 | final long identity = Binder.clearCallingIdentity(); |
| 6113 | try { |
| 6114 | String iccId = getIccId(subId); |
| 6115 | if (iccId != null) { |
| 6116 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6117 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6118 | } |
| 6119 | return null; |
| 6120 | } finally { |
| 6121 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6122 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6123 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6124 | |
| 6125 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6126 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6127 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6128 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6129 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6130 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6131 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6132 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6133 | return null; |
| 6134 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6135 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6136 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6137 | // the process, where TelephonyManager was instantiated. |
| 6138 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6139 | final long identity = Binder.clearCallingIdentity(); |
| 6140 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6141 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6142 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6143 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6144 | |
| 6145 | // Figure out what subscribers are currently active |
| 6146 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6147 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6148 | // Only consider subs which match the current subId |
| 6149 | // This logic can be simplified. See b/131189269 for progress. |
| 6150 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6151 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6152 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6153 | |
| 6154 | // First pass, find a number override for an active subscriber |
| 6155 | String mergeNumber = null; |
| 6156 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6157 | for (String key : prefs.keySet()) { |
| 6158 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6159 | final String subscriberId = (String) prefs.get(key); |
| 6160 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6161 | final String iccId = key.substring( |
| 6162 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6163 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6164 | mergeNumber = (String) prefs.get(numberKey); |
| 6165 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6166 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6167 | + " for active subscriber " + subscriberId); |
| 6168 | } |
| 6169 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6170 | break; |
| 6171 | } |
| 6172 | } |
| 6173 | } |
| 6174 | } |
| 6175 | |
| 6176 | // Shortcut when no active merged subscribers |
| 6177 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6178 | return null; |
| 6179 | } |
| 6180 | |
| 6181 | // Second pass, find all subscribers under that line override |
| 6182 | final ArraySet<String> result = new ArraySet<>(); |
| 6183 | for (String key : prefs.keySet()) { |
| 6184 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6185 | final String number = (String) prefs.get(key); |
| 6186 | if (mergeNumber.equals(number)) { |
| 6187 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6188 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6189 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6190 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6191 | result.add(subscriberId); |
| 6192 | } |
| 6193 | } |
| 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6198 | Arrays.sort(resultArray); |
| 6199 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6200 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6201 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6202 | } |
| 6203 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6204 | } finally { |
| 6205 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6206 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6207 | } |
| 6208 | |
| 6209 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6210 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6211 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6212 | |
| 6213 | final long identity = Binder.clearCallingIdentity(); |
| 6214 | try { |
| 6215 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6216 | TelephonyManager.class); |
| 6217 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6218 | if (subscriberId == null) { |
| 6219 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6220 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6221 | + subId); |
| 6222 | } |
| 6223 | return null; |
| 6224 | } |
| 6225 | |
| 6226 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6227 | .getSubscriptionInfo(subId); |
| 6228 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6229 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6230 | if (groupUuid == null) { |
| 6231 | return new String[]{subscriberId}; |
| 6232 | } |
| 6233 | |
| 6234 | // Get all subscriberIds from the group. |
| 6235 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6236 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6237 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6238 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6239 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6240 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6241 | if (subscriberId != null) { |
| 6242 | mergedSubscriberIds.add(subscriberId); |
| 6243 | } |
| 6244 | } |
| 6245 | |
| 6246 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6247 | } finally { |
| 6248 | Binder.restoreCallingIdentity(identity); |
| 6249 | |
| 6250 | } |
| 6251 | } |
| 6252 | |
| 6253 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6254 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6255 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6256 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6257 | |
| 6258 | final long identity = Binder.clearCallingIdentity(); |
| 6259 | try { |
| 6260 | final Phone phone = getPhone(subId); |
| 6261 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6262 | } finally { |
| 6263 | Binder.restoreCallingIdentity(identity); |
| 6264 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6265 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6266 | |
| 6267 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6268 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6269 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6270 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6271 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6272 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6273 | |
| 6274 | final long identity = Binder.clearCallingIdentity(); |
| 6275 | try { |
| 6276 | final Phone phone = getPhone(subId); |
| 6277 | if (phone == null) { |
| 6278 | return false; |
| 6279 | } |
| 6280 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6281 | cdmaNonRoamingList); |
| 6282 | } finally { |
| 6283 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6284 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6285 | } |
| 6286 | |
| 6287 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6288 | @Deprecated |
| 6289 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6290 | enforceModifyPermission(); |
| 6291 | |
| 6292 | int returnValue = 0; |
| 6293 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6294 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6295 | if(result.exception == null) { |
| 6296 | if (result.result != null) { |
| 6297 | byte[] responseData = (byte[])(result.result); |
| 6298 | if(responseData.length > oemResp.length) { |
| 6299 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6300 | responseData.length + "bytes. Buffer Size is " + |
| 6301 | oemResp.length + "bytes."); |
| 6302 | } |
| 6303 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6304 | returnValue = responseData.length; |
| 6305 | } |
| 6306 | } else { |
| 6307 | CommandException ex = (CommandException) result.exception; |
| 6308 | returnValue = ex.getCommandError().ordinal(); |
| 6309 | if(returnValue > 0) returnValue *= -1; |
| 6310 | } |
| 6311 | } catch (RuntimeException e) { |
| 6312 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6313 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6314 | if(returnValue > 0) returnValue *= -1; |
| 6315 | } |
| 6316 | |
| 6317 | return returnValue; |
| 6318 | } |
| 6319 | |
| 6320 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6321 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6322 | try { |
| 6323 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6324 | } catch (RuntimeException e) { |
| 6325 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6326 | } |
| 6327 | } |
| 6328 | |
| 6329 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6330 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6331 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6332 | try { |
| 6333 | TelephonyPermissions |
| 6334 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6335 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6336 | } catch (SecurityException e) { |
| 6337 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6338 | throw e; |
| 6339 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6340 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6341 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6342 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6343 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6344 | final long identity = Binder.clearCallingIdentity(); |
| 6345 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6346 | TelephonyPermissions |
| 6347 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6348 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6349 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6350 | } finally { |
| 6351 | Binder.restoreCallingIdentity(identity); |
| 6352 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6353 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6354 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6355 | |
| 6356 | @Override |
| 6357 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6358 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6359 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6360 | |
| 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6363 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6364 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | } finally { |
| 6366 | Binder.restoreCallingIdentity(identity); |
| 6367 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6368 | } |
| 6369 | |
| 6370 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6371 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6372 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6373 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6374 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6375 | return false; |
| 6376 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6377 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6378 | final long identity = Binder.clearCallingIdentity(); |
| 6379 | try { |
| 6380 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6381 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6382 | // In the long run, we may instead need to check if there exists a connection service |
| 6383 | // which can support video calling. |
| 6384 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6385 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | return imsManager.isVtEnabledByPlatform() |
| 6387 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6388 | && imsManager.isVtEnabledByUser(); |
| 6389 | } finally { |
| 6390 | Binder.restoreCallingIdentity(identity); |
| 6391 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6392 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6393 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6394 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6395 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6396 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6397 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6398 | mApp, subId, callingPackage, callingFeatureId, |
| 6399 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6400 | return false; |
| 6401 | } |
| 6402 | |
| 6403 | final long identity = Binder.clearCallingIdentity(); |
| 6404 | try { |
| 6405 | CarrierConfigManager configManager = |
| 6406 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6407 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6408 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6409 | } finally { |
| 6410 | Binder.restoreCallingIdentity(identity); |
| 6411 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6412 | } |
| 6413 | |
| 6414 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6415 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6416 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6417 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6418 | return false; |
| 6419 | } |
| 6420 | |
| 6421 | final long identity = Binder.clearCallingIdentity(); |
| 6422 | try { |
| 6423 | CarrierConfigManager configManager = |
| 6424 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6425 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6426 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6427 | } finally { |
| 6428 | Binder.restoreCallingIdentity(identity); |
| 6429 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6430 | } |
| 6431 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6432 | @Override |
| 6433 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6434 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6435 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | @Override |
| 6439 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6440 | final long identity = Binder.clearCallingIdentity(); |
| 6441 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6442 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6443 | } finally { |
| 6444 | Binder.restoreCallingIdentity(identity); |
| 6445 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6446 | } |
| 6447 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6448 | /** |
| 6449 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6450 | * support for the feature and device firmware support. |
| 6451 | * |
| 6452 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6453 | */ |
| 6454 | @Override |
| 6455 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6456 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6457 | final Phone phone = getPhone(subscriptionId); |
| 6458 | if (phone == null) { |
| 6459 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6460 | return false; |
| 6461 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6462 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6463 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6464 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6465 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6466 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6467 | return isCarrierSupported && isDeviceSupported; |
| 6468 | } finally { |
| 6469 | Binder.restoreCallingIdentity(identity); |
| 6470 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6471 | } |
| 6472 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6473 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6474 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6475 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6476 | * 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] | 6477 | */ |
| 6478 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6479 | final long identity = Binder.clearCallingIdentity(); |
| 6480 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6481 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6482 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6483 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6484 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6485 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6486 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6487 | } finally { |
| 6488 | Binder.restoreCallingIdentity(identity); |
| 6489 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6490 | } |
| 6491 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6492 | @Deprecated |
| 6493 | @Override |
| 6494 | public String getDeviceId(String callingPackage) { |
| 6495 | return getDeviceIdWithFeature(callingPackage, null); |
| 6496 | } |
| 6497 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6498 | /** |
| 6499 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6500 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6501 | * |
| 6502 | * <p>Requires Permission: |
| 6503 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6504 | */ |
| 6505 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6506 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6507 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6508 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6509 | return null; |
| 6510 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6511 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6512 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6513 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6514 | return null; |
| 6515 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6516 | |
| 6517 | final long identity = Binder.clearCallingIdentity(); |
| 6518 | try { |
| 6519 | return phone.getDeviceId(); |
| 6520 | } finally { |
| 6521 | Binder.restoreCallingIdentity(identity); |
| 6522 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6523 | } |
| 6524 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6525 | /** |
| 6526 | * {@hide} |
| 6527 | * Returns the IMS Registration Status on a particular subid |
| 6528 | * |
| 6529 | * @param subId |
| 6530 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6531 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6532 | Phone phone = getPhone(subId); |
| 6533 | if (phone != null) { |
| 6534 | return phone.isImsRegistered(); |
| 6535 | } else { |
| 6536 | return false; |
| 6537 | } |
| 6538 | } |
| 6539 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6540 | @Override |
| 6541 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6542 | final long identity = Binder.clearCallingIdentity(); |
| 6543 | try { |
| 6544 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6545 | } finally { |
| 6546 | Binder.restoreCallingIdentity(identity); |
| 6547 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6548 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6549 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6550 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6551 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6552 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6553 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6554 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6555 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6556 | } |
| 6557 | final long identity = Binder.clearCallingIdentity(); |
| 6558 | try { |
| 6559 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6560 | } finally { |
| 6561 | Binder.restoreCallingIdentity(identity); |
| 6562 | } |
| 6563 | } |
| 6564 | |
| 6565 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6566 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6567 | final long identity = Binder.clearCallingIdentity(); |
| 6568 | try { |
| 6569 | Phone phone = getPhone(subscriptionId); |
| 6570 | if (phone == null) { |
| 6571 | return null; |
| 6572 | } |
| 6573 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6574 | } finally { |
| 6575 | Binder.restoreCallingIdentity(identity); |
| 6576 | } |
| 6577 | } |
| 6578 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6579 | /** |
| 6580 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6581 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6582 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | final long identity = Binder.clearCallingIdentity(); |
| 6584 | try { |
| 6585 | Phone phone = getPhone(subId); |
| 6586 | if (phone != null) { |
| 6587 | return phone.isWifiCallingEnabled(); |
| 6588 | } else { |
| 6589 | return false; |
| 6590 | } |
| 6591 | } finally { |
| 6592 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6593 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6594 | } |
| 6595 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6596 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6597 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6598 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6599 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6600 | final long identity = Binder.clearCallingIdentity(); |
| 6601 | try { |
| 6602 | Phone phone = getPhone(subId); |
| 6603 | if (phone != null) { |
| 6604 | return phone.isVideoEnabled(); |
| 6605 | } else { |
| 6606 | return false; |
| 6607 | } |
| 6608 | } finally { |
| 6609 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | /** |
| 6614 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6615 | * defined in {@link ImsRegistrationImplBase}. |
| 6616 | */ |
| 6617 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6618 | final long identity = Binder.clearCallingIdentity(); |
| 6619 | try { |
| 6620 | Phone phone = getPhone(subId); |
| 6621 | if (phone != null) { |
| 6622 | return phone.getImsRegistrationTech(); |
| 6623 | } else { |
| 6624 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6625 | } |
| 6626 | } finally { |
| 6627 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6628 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6629 | } |
| 6630 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6631 | @Override |
| 6632 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6633 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6634 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6635 | return; |
| 6636 | } |
| 6637 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6638 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6639 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6640 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6641 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6642 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6643 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6644 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6645 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6646 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6647 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6648 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6649 | // There has been issues when Sms raw table somehow stores orphan |
| 6650 | // fragments. They lead to garbled message when new fragments come |
| 6651 | // in and combined with those stale ones. In case this happens again, |
| 6652 | // user can reset all network settings which will clean up this table. |
| 6653 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6654 | // Clean up IMS settings as well here. |
| 6655 | int slotId = getSlotIndex(subId); |
| 6656 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6657 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6658 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6659 | |
| 6660 | // Erase modem config if erase modem on network setting is enabled. |
| 6661 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6662 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6663 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6664 | sendEraseModemConfig(getDefaultPhone()); |
| 6665 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6666 | } finally { |
| 6667 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6668 | } |
| 6669 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6670 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6671 | private void cleanUpSmsRawTable(Context context) { |
| 6672 | ContentResolver resolver = context.getContentResolver(); |
| 6673 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6674 | resolver.delete(uri, null, null); |
| 6675 | } |
| 6676 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6677 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6678 | public String getSimLocaleForSubscriber(int subId) { |
| 6679 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6680 | final Phone phone = getPhone(subId); |
| 6681 | if (phone == null) { |
| 6682 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6683 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6684 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6685 | final long identity = Binder.clearCallingIdentity(); |
| 6686 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6687 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6688 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6689 | if (info == null) { |
| 6690 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6691 | return null; |
| 6692 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6693 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6694 | // preferences (EF-PL and EF-LI)... |
| 6695 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6696 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6697 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6698 | if (localeFromDefaultSim != null) { |
| 6699 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6700 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6701 | + localeFromDefaultSim); |
| 6702 | return localeFromDefaultSim.toLanguageTag(); |
| 6703 | } else { |
| 6704 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | } |
| 6706 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6707 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6708 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6709 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6710 | // the SIM and carrier preferences does not include a country we add the country |
| 6711 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6712 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6713 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6714 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | return mccLocale.toLanguageTag(); |
| 6716 | } |
| 6717 | |
| 6718 | if (DBG) log("No locale found - returning null"); |
| 6719 | return null; |
| 6720 | } finally { |
| 6721 | Binder.restoreCallingIdentity(identity); |
| 6722 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6723 | } |
| 6724 | |
| 6725 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6726 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6727 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6728 | } |
| 6729 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6730 | /** |
| 6731 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6732 | */ |
| 6733 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6734 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6735 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6736 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6737 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6738 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6739 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6740 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6741 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6742 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6743 | * representing the state of the modem. |
| 6744 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6745 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6746 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6747 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6748 | */ |
| 6749 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6750 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6751 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6752 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6753 | |
| 6754 | final long identity = Binder.clearCallingIdentity(); |
| 6755 | try { |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 6756 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6757 | } finally { |
| 6758 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6759 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6760 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6761 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6762 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6763 | // less than total activity duration. |
| 6764 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6765 | if (info == null) { |
| 6766 | return false; |
| 6767 | } |
| 6768 | int activityDurationMs = |
| 6769 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6770 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6771 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6772 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6773 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6774 | } |
| 6775 | return (info.isValid() |
| 6776 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6777 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6778 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6779 | && (totalTxTimeMs <= activityDurationMs)); |
| 6780 | } |
| 6781 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6782 | /** |
| 6783 | * {@hide} |
| 6784 | * Returns the service state information on specified subscription. |
| 6785 | */ |
| 6786 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6787 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6788 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6789 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6790 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6791 | return null; |
| 6792 | } |
| 6793 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6794 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6795 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6796 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6797 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6798 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6799 | .setCallingPid(Binder.getCallingPid()) |
| 6800 | .setCallingUid(Binder.getCallingUid()) |
| 6801 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6802 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6803 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6804 | .build()); |
| 6805 | |
| 6806 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6807 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6808 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6809 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6810 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6811 | .setCallingPid(Binder.getCallingPid()) |
| 6812 | .setCallingUid(Binder.getCallingUid()) |
| 6813 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6814 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6815 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6816 | .build()); |
| 6817 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6818 | boolean hasFinePermission = |
| 6819 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6820 | boolean hasCoarsePermission = |
| 6821 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6822 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6823 | final long identity = Binder.clearCallingIdentity(); |
| 6824 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 6825 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 6826 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 6827 | Rlog.d(LOG_TAG, |
| 6828 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 6829 | return null; |
| 6830 | } |
| 6831 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6832 | final Phone phone = getPhone(subId); |
| 6833 | if (phone == null) { |
| 6834 | return null; |
| 6835 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6836 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6837 | ServiceState ss = phone.getServiceState(); |
| 6838 | |
| 6839 | // Scrub out the location info in ServiceState depending on what level of access |
| 6840 | // the caller has. |
| 6841 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6842 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6843 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6844 | } finally { |
| 6845 | Binder.restoreCallingIdentity(identity); |
| 6846 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6847 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6848 | |
| 6849 | /** |
| 6850 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6851 | * |
| 6852 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6853 | * voicemail ringtone. |
| 6854 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6855 | * PhoneAccount. |
| 6856 | */ |
| 6857 | @Override |
| 6858 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6859 | final long identity = Binder.clearCallingIdentity(); |
| 6860 | try { |
| 6861 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6862 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6863 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6864 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6865 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6866 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6867 | } finally { |
| 6868 | Binder.restoreCallingIdentity(identity); |
| 6869 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6870 | } |
| 6871 | |
| 6872 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6873 | * Sets the per-account voicemail ringtone. |
| 6874 | * |
| 6875 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6876 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6877 | * |
| 6878 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6879 | * voicemail ringtone. |
| 6880 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6881 | * PhoneAccount. |
| 6882 | */ |
| 6883 | @Override |
| 6884 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6885 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6886 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6887 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6888 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6889 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6890 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6891 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6892 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6893 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6894 | |
| 6895 | final long identity = Binder.clearCallingIdentity(); |
| 6896 | try { |
| 6897 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6898 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6899 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6900 | } |
| 6901 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6902 | } finally { |
| 6903 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6904 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6905 | } |
| 6906 | |
| 6907 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6908 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6909 | * |
| 6910 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6911 | * voicemail vibration setting. |
| 6912 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6913 | */ |
| 6914 | @Override |
| 6915 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6916 | final long identity = Binder.clearCallingIdentity(); |
| 6917 | try { |
| 6918 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6919 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6920 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6921 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6922 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6923 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6924 | } finally { |
| 6925 | Binder.restoreCallingIdentity(identity); |
| 6926 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6927 | } |
| 6928 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6929 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6930 | * Sets the per-account voicemail vibration. |
| 6931 | * |
| 6932 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6933 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6934 | * |
| 6935 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6936 | * voicemail vibration setting. |
| 6937 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6938 | * specific PhoneAccount. |
| 6939 | */ |
| 6940 | @Override |
| 6941 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6942 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6943 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6944 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6945 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6946 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6947 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6948 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6949 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6950 | } |
| 6951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6952 | final long identity = Binder.clearCallingIdentity(); |
| 6953 | try { |
| 6954 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6955 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6956 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6957 | } |
| 6958 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6959 | } finally { |
| 6960 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6961 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6962 | } |
| 6963 | |
| 6964 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6965 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6966 | * |
| 6967 | * @throws SecurityException if the caller does not have the required permission |
| 6968 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6969 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6970 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6971 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6975 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6976 | * permission. |
| 6977 | * |
| 6978 | * @throws SecurityException if the caller does not have the required permission |
| 6979 | */ |
| 6980 | private void enforceSendSmsPermission() { |
| 6981 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6982 | } |
| 6983 | |
| 6984 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6985 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6986 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6987 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6988 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6989 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6990 | final long identity = Binder.clearCallingIdentity(); |
| 6991 | try { |
| 6992 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6993 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6994 | if (componentName == null) { |
| 6995 | throw new SecurityException( |
| 6996 | "Caller not current active visual voicemail package[null]"); |
| 6997 | } |
| 6998 | String vvmPackage = componentName.getPackageName(); |
| 6999 | if (!callingPackage.equals(vvmPackage)) { |
| 7000 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7001 | + vvmPackage + "]"); |
| 7002 | } |
| 7003 | } finally { |
| 7004 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7005 | } |
| 7006 | } |
| 7007 | |
| 7008 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7009 | * Return the application ID for the app type. |
| 7010 | * |
| 7011 | * @param subId the subscription ID that this request applies to. |
| 7012 | * @param appType the uicc app type. |
| 7013 | * @return Application ID for specificied app type, or null if no uicc. |
| 7014 | */ |
| 7015 | @Override |
| 7016 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7017 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7018 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7021 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7022 | if (phone == null) { |
| 7023 | return null; |
| 7024 | } |
| 7025 | String aid = null; |
| 7026 | try { |
| 7027 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7028 | .getApplicationByType(appType).getAid(); |
| 7029 | } catch (Exception e) { |
| 7030 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7031 | } |
| 7032 | return aid; |
| 7033 | } finally { |
| 7034 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7035 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7036 | } |
| 7037 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7038 | /** |
| 7039 | * Return the Electronic Serial Number. |
| 7040 | * |
| 7041 | * @param subId the subscription ID that this request applies to. |
| 7042 | * @return ESN or null if error. |
| 7043 | */ |
| 7044 | @Override |
| 7045 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7046 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7047 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7048 | |
| 7049 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7050 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7051 | if (phone == null) { |
| 7052 | return null; |
| 7053 | } |
| 7054 | String esn = null; |
| 7055 | try { |
| 7056 | esn = phone.getEsn(); |
| 7057 | } catch (Exception e) { |
| 7058 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7059 | } |
| 7060 | return esn; |
| 7061 | } finally { |
| 7062 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7063 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7064 | } |
| 7065 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7066 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7067 | * Return the Preferred Roaming List Version. |
| 7068 | * |
| 7069 | * @param subId the subscription ID that this request applies to. |
| 7070 | * @return PRLVersion or null if error. |
| 7071 | */ |
| 7072 | @Override |
| 7073 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7074 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7075 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7076 | |
| 7077 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7078 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | if (phone == null) { |
| 7080 | return null; |
| 7081 | } |
| 7082 | String cdmaPrlVersion = null; |
| 7083 | try { |
| 7084 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7085 | } catch (Exception e) { |
| 7086 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7087 | } |
| 7088 | return cdmaPrlVersion; |
| 7089 | } finally { |
| 7090 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7091 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7092 | } |
| 7093 | |
| 7094 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7095 | * Get snapshot of Telephony histograms |
| 7096 | * @return List of Telephony histograms |
| 7097 | * @hide |
| 7098 | */ |
| 7099 | @Override |
| 7100 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7102 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7103 | |
| 7104 | final long identity = Binder.clearCallingIdentity(); |
| 7105 | try { |
| 7106 | return RIL.getTelephonyRILTimingHistograms(); |
| 7107 | } finally { |
| 7108 | Binder.restoreCallingIdentity(identity); |
| 7109 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7110 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7111 | |
| 7112 | /** |
| 7113 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7114 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7115 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7116 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7117 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7118 | * @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] | 7119 | */ |
| 7120 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7121 | @TelephonyManager.SetCarrierRestrictionResult |
| 7122 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7123 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7124 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7125 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7126 | if (carrierRestrictionRules == null) { |
| 7127 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7128 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7129 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7130 | final long identity = Binder.clearCallingIdentity(); |
| 7131 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7132 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7133 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7134 | } finally { |
| 7135 | Binder.restoreCallingIdentity(identity); |
| 7136 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | /** |
| 7140 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7141 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7142 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7143 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7144 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7145 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7146 | */ |
| 7147 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7148 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7149 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7150 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7151 | |
| 7152 | final long identity = Binder.clearCallingIdentity(); |
| 7153 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7154 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7155 | if (response instanceof CarrierRestrictionRules) { |
| 7156 | return (CarrierRestrictionRules) response; |
| 7157 | } |
| 7158 | // Response is an Exception of some kind, |
| 7159 | // which is signalled to the user as a NULL retval |
| 7160 | return null; |
| 7161 | } catch (Exception e) { |
| 7162 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7163 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7164 | } finally { |
| 7165 | Binder.restoreCallingIdentity(identity); |
| 7166 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7167 | } |
| 7168 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7169 | /** |
| 7170 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7171 | * @param subId the subscription ID that this action applies to. |
| 7172 | * @param enabled control enable or disable metered apns. |
| 7173 | * {@hide} |
| 7174 | */ |
| 7175 | @Override |
| 7176 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7177 | enforceModifyPermission(); |
| 7178 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | |
| 7180 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7181 | if (phone == null) { |
| 7182 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7183 | return; |
| 7184 | } |
| 7185 | try { |
| 7186 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7187 | } catch (Exception e) { |
| 7188 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7189 | } finally { |
| 7190 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7191 | } |
| 7192 | } |
| 7193 | |
| 7194 | /** |
| 7195 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7196 | * @param subId the subscription ID that this action applies to. |
| 7197 | * @param enabled control enable or disable radio. |
| 7198 | * {@hide} |
| 7199 | */ |
| 7200 | @Override |
| 7201 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7202 | enforceModifyPermission(); |
| 7203 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7204 | |
| 7205 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7206 | if (phone == null) { |
| 7207 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7208 | return; |
| 7209 | } |
| 7210 | try { |
| 7211 | phone.carrierActionSetRadioEnabled(enabled); |
| 7212 | } catch (Exception e) { |
| 7213 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | } finally { |
| 7215 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7216 | } |
| 7217 | } |
| 7218 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7219 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7220 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7221 | * network status based on which carrier apps could apply actions accordingly, |
| 7222 | * enable/disable default url handler for example. |
| 7223 | * |
| 7224 | * @param subId the subscription ID that this action applies to. |
| 7225 | * @param report control start/stop reporting the default network status. |
| 7226 | * {@hide} |
| 7227 | */ |
| 7228 | @Override |
| 7229 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7230 | enforceModifyPermission(); |
| 7231 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7232 | |
| 7233 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7234 | if (phone == null) { |
| 7235 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7236 | return; |
| 7237 | } |
| 7238 | try { |
| 7239 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7240 | } catch (Exception e) { |
| 7241 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7242 | } finally { |
| 7243 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7244 | } |
| 7245 | } |
| 7246 | |
| 7247 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7248 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7249 | * @param subId the subscription ID that this action applies to. |
| 7250 | * {@hide} |
| 7251 | */ |
| 7252 | @Override |
| 7253 | public void carrierActionResetAll(int subId) { |
| 7254 | enforceModifyPermission(); |
| 7255 | final Phone phone = getPhone(subId); |
| 7256 | if (phone == null) { |
| 7257 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7258 | return; |
| 7259 | } |
| 7260 | try { |
| 7261 | phone.carrierActionResetAll(); |
| 7262 | } catch (Exception e) { |
| 7263 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7264 | } |
| 7265 | } |
| 7266 | |
| 7267 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7268 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7269 | * bug report is being generated. |
| 7270 | */ |
| 7271 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7272 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7273 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7274 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7275 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7276 | + Binder.getCallingPid() |
| 7277 | + ", uid=" + Binder.getCallingUid() |
| 7278 | + "without permission " |
| 7279 | + android.Manifest.permission.DUMP); |
| 7280 | return; |
| 7281 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7282 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7283 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7284 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7285 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7286 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7287 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7288 | @NonNull String[] args) { |
| 7289 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7290 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7291 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7292 | } |
| 7293 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7294 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7295 | * Policy control of data connection. Usually used when data limit is passed. |
| 7296 | * @param enabled True if enabling the data, otherwise disabling. |
| 7297 | * @param subId Subscription index |
| 7298 | * {@hide} |
| 7299 | */ |
| 7300 | @Override |
| 7301 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7302 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7303 | |
| 7304 | final long identity = Binder.clearCallingIdentity(); |
| 7305 | try { |
| 7306 | Phone phone = getPhone(subId); |
| 7307 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7308 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7309 | } |
| 7310 | } finally { |
| 7311 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7312 | } |
| 7313 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7314 | |
| 7315 | /** |
| 7316 | * Get Client request stats |
| 7317 | * @return List of Client Request Stats |
| 7318 | * @hide |
| 7319 | */ |
| 7320 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7321 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7322 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7323 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7324 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7325 | return null; |
| 7326 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7327 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7328 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7329 | final long identity = Binder.clearCallingIdentity(); |
| 7330 | try { |
| 7331 | if (phone != null) { |
| 7332 | return phone.getClientRequestStats(); |
| 7333 | } |
| 7334 | |
| 7335 | return null; |
| 7336 | } finally { |
| 7337 | Binder.restoreCallingIdentity(identity); |
| 7338 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7339 | } |
| 7340 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7341 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7342 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7343 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7344 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7345 | |
| 7346 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7347 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7348 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7349 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7350 | * @param state State of SIM (power down, power up, pass through) |
| 7351 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7352 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7353 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7354 | * |
| 7355 | **/ |
| 7356 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7357 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7358 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7359 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7360 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7361 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7362 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7363 | final long identity = Binder.clearCallingIdentity(); |
| 7364 | try { |
| 7365 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7366 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7367 | } |
| 7368 | } finally { |
| 7369 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7370 | } |
| 7371 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7372 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7373 | private boolean isUssdApiAllowed(int subId) { |
| 7374 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7375 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7376 | if (configManager == null) { |
| 7377 | return false; |
| 7378 | } |
| 7379 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7380 | if (pb == null) { |
| 7381 | return false; |
| 7382 | } |
| 7383 | return pb.getBoolean( |
| 7384 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7385 | } |
| 7386 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7387 | /** |
| 7388 | * Check if phone is in emergency callback mode |
| 7389 | * @return true if phone is in emergency callback mode |
| 7390 | * @param subId sub id |
| 7391 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7392 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7393 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7394 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7395 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7396 | |
| 7397 | final long identity = Binder.clearCallingIdentity(); |
| 7398 | try { |
| 7399 | if (phone != null) { |
| 7400 | return phone.isInEcm(); |
| 7401 | } else { |
| 7402 | return false; |
| 7403 | } |
| 7404 | } finally { |
| 7405 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7406 | } |
| 7407 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7408 | |
| 7409 | /** |
| 7410 | * Get the current signal strength information for the given subscription. |
| 7411 | * Because this information is not updated when the device is in a low power state |
| 7412 | * it should not be relied-upon to be current. |
| 7413 | * @param subId Subscription index |
| 7414 | * @return the most recent cached signal strength info from the modem |
| 7415 | */ |
| 7416 | @Override |
| 7417 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7418 | final long identity = Binder.clearCallingIdentity(); |
| 7419 | try { |
| 7420 | Phone p = getPhone(subId); |
| 7421 | if (p == null) { |
| 7422 | return null; |
| 7423 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7424 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7425 | return p.getSignalStrength(); |
| 7426 | } finally { |
| 7427 | Binder.restoreCallingIdentity(identity); |
| 7428 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7429 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7430 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7431 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7432 | * Get the current modem radio state for the given slot. |
| 7433 | * @param slotIndex slot index. |
| 7434 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7435 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7436 | * @return the current radio power state from the modem |
| 7437 | */ |
| 7438 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7439 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7440 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7441 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7442 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7443 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7444 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7445 | } |
| 7446 | |
| 7447 | final long identity = Binder.clearCallingIdentity(); |
| 7448 | try { |
| 7449 | return phone.getRadioPowerState(); |
| 7450 | } finally { |
| 7451 | Binder.restoreCallingIdentity(identity); |
| 7452 | } |
| 7453 | } |
| 7454 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7455 | } |
| 7456 | |
| 7457 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7458 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7459 | * |
| 7460 | * <p>Requires one of the following permissions: |
| 7461 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7462 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7463 | * privileges. |
| 7464 | * |
| 7465 | * @param subId subscription id |
| 7466 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7467 | * {@code false}. |
| 7468 | */ |
| 7469 | @Override |
| 7470 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7471 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7472 | null /* message */); |
| 7473 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7474 | boolean isEnabled = false; |
| 7475 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7476 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7477 | Phone phone = getPhone(subId); |
| 7478 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7479 | } catch (Exception e) { |
| 7480 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7481 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7482 | } finally { |
| 7483 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7484 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7485 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7486 | } |
| 7487 | |
| 7488 | |
| 7489 | /** |
| 7490 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7491 | * |
| 7492 | * <p> Requires permission: |
| 7493 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7494 | * privileges. |
| 7495 | * |
| 7496 | * @param subId subscription id |
| 7497 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7498 | */ |
| 7499 | @Override |
| 7500 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7501 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7502 | mApp, subId, "setDataRoamingEnabled"); |
| 7503 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7504 | final long identity = Binder.clearCallingIdentity(); |
| 7505 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7506 | Phone phone = getPhone(subId); |
| 7507 | if (phone != null) { |
| 7508 | phone.setDataRoamingEnabled(isEnabled); |
| 7509 | } |
| 7510 | } finally { |
| 7511 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7512 | } |
| 7513 | } |
| 7514 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7515 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7516 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7517 | TelephonyPermissions |
| 7518 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7519 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7520 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7521 | boolean isAllowed = true; |
| 7522 | final long identity = Binder.clearCallingIdentity(); |
| 7523 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7524 | Phone phone = getPhone(subId); |
| 7525 | if (phone != null) { |
| 7526 | isAllowed = phone.isCspPlmnEnabled(); |
| 7527 | } |
| 7528 | } finally { |
| 7529 | Binder.restoreCallingIdentity(identity); |
| 7530 | } |
| 7531 | return isAllowed; |
| 7532 | } |
| 7533 | |
| 7534 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7535 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7536 | // Verify that tha callingPackage belongs to the calling UID |
| 7537 | mApp.getSystemService(AppOpsManager.class) |
| 7538 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7539 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7540 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7541 | try { |
| 7542 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7543 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7544 | } catch (SecurityException e) { |
| 7545 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7546 | // has carrier privileges on an active UICC |
| 7547 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7548 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7549 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7550 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7551 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7552 | |
| 7553 | final long identity = Binder.clearCallingIdentity(); |
| 7554 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7555 | UiccController uiccController = UiccController.getInstance(); |
| 7556 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7557 | if (hasReadPermission) { |
| 7558 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7559 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7560 | |
| 7561 | // Remove private info if the caller doesn't have access |
| 7562 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7563 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7564 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7565 | // is available |
| 7566 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7567 | if (card == null || card.getUiccProfile() == null) { |
| 7568 | // assume no access if the card or profile is unavailable |
| 7569 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7570 | continue; |
| 7571 | } |
| 7572 | UiccProfile profile = card.getUiccProfile(); |
| 7573 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7574 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7575 | filteredInfos.add(cardInfo); |
| 7576 | } else { |
| 7577 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7578 | } |
| 7579 | } |
| 7580 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7581 | } finally { |
| 7582 | Binder.restoreCallingIdentity(identity); |
| 7583 | } |
| 7584 | } |
| 7585 | |
| 7586 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7587 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7588 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7589 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7590 | final long identity = Binder.clearCallingIdentity(); |
| 7591 | try { |
| 7592 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7593 | if (slots == null) { |
| 7594 | Rlog.i(LOG_TAG, "slots is null."); |
| 7595 | return null; |
| 7596 | } |
| 7597 | |
| 7598 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7599 | for (int i = 0; i < slots.length; i++) { |
| 7600 | UiccSlot slot = slots[i]; |
| 7601 | if (slot == null) { |
| 7602 | continue; |
| 7603 | } |
| 7604 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7605 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7606 | UiccCard card = slot.getUiccCard(); |
| 7607 | if (card != null) { |
| 7608 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7609 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7610 | cardId = slot.getEid(); |
| 7611 | if (TextUtils.isEmpty(cardId)) { |
| 7612 | cardId = slot.getIccId(); |
| 7613 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7614 | } |
| 7615 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7616 | if (cardId != null) { |
| 7617 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7618 | // if cardId is an EID, it's all digits so this is fine |
| 7619 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7620 | } |
| 7621 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7622 | int cardState = 0; |
| 7623 | switch (slot.getCardState()) { |
| 7624 | case CARDSTATE_ABSENT: |
| 7625 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7626 | break; |
| 7627 | case CARDSTATE_PRESENT: |
| 7628 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7629 | break; |
| 7630 | case CARDSTATE_ERROR: |
| 7631 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7632 | break; |
| 7633 | case CARDSTATE_RESTRICTED: |
| 7634 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7635 | break; |
| 7636 | default: |
| 7637 | break; |
| 7638 | |
| 7639 | } |
| 7640 | |
| 7641 | infos[i] = new UiccSlotInfo( |
| 7642 | slot.isActive(), |
| 7643 | slot.isEuicc(), |
| 7644 | cardId, |
| 7645 | cardState, |
| 7646 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7647 | slot.isExtendedApduSupported(), |
| 7648 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7649 | } |
| 7650 | return infos; |
| 7651 | } finally { |
| 7652 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7653 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | @Override |
| 7657 | public boolean switchSlots(int[] physicalSlots) { |
| 7658 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7659 | |
| 7660 | final long identity = Binder.clearCallingIdentity(); |
| 7661 | try { |
| 7662 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7663 | } finally { |
| 7664 | Binder.restoreCallingIdentity(identity); |
| 7665 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7666 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7667 | |
| 7668 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7669 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7670 | final long identity = Binder.clearCallingIdentity(); |
| 7671 | try { |
| 7672 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7673 | } finally { |
| 7674 | Binder.restoreCallingIdentity(identity); |
| 7675 | } |
| 7676 | } |
| 7677 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7678 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7679 | * A test API to reload the UICC profile. |
| 7680 | * |
| 7681 | * <p>Requires that the calling app has permission |
| 7682 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7683 | * @hide |
| 7684 | */ |
| 7685 | @Override |
| 7686 | public void refreshUiccProfile(int subId) { |
| 7687 | enforceModifyPermission(); |
| 7688 | |
| 7689 | final long identity = Binder.clearCallingIdentity(); |
| 7690 | try { |
| 7691 | Phone phone = getPhone(subId); |
| 7692 | if (phone == null) { |
| 7693 | return; |
| 7694 | } |
| 7695 | UiccCard uiccCard = phone.getUiccCard(); |
| 7696 | if (uiccCard == null) { |
| 7697 | return; |
| 7698 | } |
| 7699 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7700 | if (uiccProfile == null) { |
| 7701 | return; |
| 7702 | } |
| 7703 | uiccProfile.refresh(); |
| 7704 | } finally { |
| 7705 | Binder.restoreCallingIdentity(identity); |
| 7706 | } |
| 7707 | } |
| 7708 | |
| 7709 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7710 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7711 | */ |
| 7712 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7713 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7714 | } |
| 7715 | |
| 7716 | /** |
| 7717 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7718 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7719 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7720 | */ |
| 7721 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7722 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7723 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 7724 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7725 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7726 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7727 | return isDataRoamingEnabled; |
| 7728 | } |
| 7729 | |
| 7730 | /** |
| 7731 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7732 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7733 | */ |
| 7734 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7735 | List<Integer> list = TelephonyProperties.default_network(); |
| 7736 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7737 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7738 | return list.get(phoneId); |
| 7739 | } |
| 7740 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7741 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7742 | |
| 7743 | @Override |
| 7744 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7745 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7746 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7747 | |
| 7748 | final long identity = Binder.clearCallingIdentity(); |
| 7749 | try { |
| 7750 | final Phone phone = getPhone(subId); |
| 7751 | if (phone == null) { |
| 7752 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7753 | return; |
| 7754 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7755 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7756 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7757 | } finally { |
| 7758 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7759 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7760 | } |
| 7761 | |
| 7762 | @Override |
| 7763 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7764 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7765 | |
| 7766 | final long identity = Binder.clearCallingIdentity(); |
| 7767 | try { |
| 7768 | final Phone phone = getPhone(subId); |
| 7769 | if (phone == null) { |
| 7770 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7771 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7772 | } |
| 7773 | return phone.getCarrierIdListVersion(); |
| 7774 | } finally { |
| 7775 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7776 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7777 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7778 | |
| 7779 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7780 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7781 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7782 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7783 | mApp, subId, callingPackage, callingFeatureId, |
| 7784 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7785 | return -1; |
| 7786 | } |
| 7787 | |
| 7788 | final long identity = Binder.clearCallingIdentity(); |
| 7789 | try { |
| 7790 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7791 | } finally { |
| 7792 | Binder.restoreCallingIdentity(identity); |
| 7793 | } |
| 7794 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7795 | |
| 7796 | @Override |
| 7797 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7798 | TelephonyPermissions |
| 7799 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7800 | mApp, subId, "getCdmaRoamingMode"); |
| 7801 | |
| 7802 | final long identity = Binder.clearCallingIdentity(); |
| 7803 | try { |
| 7804 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7805 | } finally { |
| 7806 | Binder.restoreCallingIdentity(identity); |
| 7807 | } |
| 7808 | } |
| 7809 | |
| 7810 | @Override |
| 7811 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7812 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7813 | mApp, subId, "setCdmaRoamingMode"); |
| 7814 | |
| 7815 | final long identity = Binder.clearCallingIdentity(); |
| 7816 | try { |
| 7817 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7818 | } finally { |
| 7819 | Binder.restoreCallingIdentity(identity); |
| 7820 | } |
| 7821 | } |
| 7822 | |
| 7823 | @Override |
| 7824 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7825 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7826 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7827 | |
| 7828 | final long identity = Binder.clearCallingIdentity(); |
| 7829 | try { |
| 7830 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7831 | } finally { |
| 7832 | Binder.restoreCallingIdentity(identity); |
| 7833 | } |
| 7834 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7835 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7836 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7837 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7838 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7839 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7840 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7841 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7842 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7843 | } |
| 7844 | final long identity = Binder.clearCallingIdentity(); |
| 7845 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7846 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7847 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7848 | if (phone.getEmergencyNumberTracker() != null |
| 7849 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7850 | emergencyNumberListInternal.put( |
| 7851 | phone.getSubId(), |
| 7852 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7853 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7854 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7855 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7856 | } finally { |
| 7857 | Binder.restoreCallingIdentity(identity); |
| 7858 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7859 | } |
| 7860 | |
| 7861 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7862 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7863 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7864 | if (!exactMatch) { |
| 7865 | TelephonyPermissions |
| 7866 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7867 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7868 | } |
| 7869 | final long identity = Binder.clearCallingIdentity(); |
| 7870 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7871 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7872 | if (phone.getEmergencyNumberTracker() != null |
| 7873 | && phone.getEmergencyNumberTracker() != null) { |
| 7874 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7875 | number, exactMatch)) { |
| 7876 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7877 | } |
| 7878 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7879 | } |
| 7880 | return false; |
| 7881 | } finally { |
| 7882 | Binder.restoreCallingIdentity(identity); |
| 7883 | } |
| 7884 | } |
| 7885 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7886 | /** |
| 7887 | * Update emergency number list for test mode. |
| 7888 | */ |
| 7889 | @Override |
| 7890 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7891 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7892 | "updateEmergencyNumberListTestMode"); |
| 7893 | |
| 7894 | final long identity = Binder.clearCallingIdentity(); |
| 7895 | try { |
| 7896 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7897 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7898 | if (tracker != null) { |
| 7899 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7900 | } |
| 7901 | } |
| 7902 | } finally { |
| 7903 | Binder.restoreCallingIdentity(identity); |
| 7904 | } |
| 7905 | } |
| 7906 | |
| 7907 | /** |
| 7908 | * Get the full emergency number list for test mode. |
| 7909 | */ |
| 7910 | @Override |
| 7911 | public List<String> getEmergencyNumberListTestMode() { |
| 7912 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7913 | "getEmergencyNumberListTestMode"); |
| 7914 | |
| 7915 | final long identity = Binder.clearCallingIdentity(); |
| 7916 | try { |
| 7917 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7918 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7919 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7920 | if (tracker != null) { |
| 7921 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7922 | emergencyNumbers.add(num.getNumber()); |
| 7923 | } |
| 7924 | } |
| 7925 | } |
| 7926 | return new ArrayList<>(emergencyNumbers); |
| 7927 | } finally { |
| 7928 | Binder.restoreCallingIdentity(identity); |
| 7929 | } |
| 7930 | } |
| 7931 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7932 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7933 | public int getEmergencyNumberDbVersion(int subId) { |
| 7934 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7935 | |
| 7936 | final long identity = Binder.clearCallingIdentity(); |
| 7937 | try { |
| 7938 | final Phone phone = getPhone(subId); |
| 7939 | if (phone == null) { |
| 7940 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7941 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7942 | } |
| 7943 | return phone.getEmergencyNumberDbVersion(); |
| 7944 | } finally { |
| 7945 | Binder.restoreCallingIdentity(identity); |
| 7946 | } |
| 7947 | } |
| 7948 | |
| 7949 | @Override |
| 7950 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7951 | enforceModifyPermission(); |
| 7952 | |
| 7953 | final long identity = Binder.clearCallingIdentity(); |
| 7954 | try { |
| 7955 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7956 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7957 | if (tracker != null) { |
| 7958 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7959 | } |
| 7960 | } |
| 7961 | } finally { |
| 7962 | Binder.restoreCallingIdentity(identity); |
| 7963 | } |
| 7964 | } |
| 7965 | |
| 7966 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7967 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7968 | enforceActiveEmergencySessionPermission(); |
| 7969 | |
| 7970 | final long identity = Binder.clearCallingIdentity(); |
| 7971 | try { |
| 7972 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7973 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7974 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7975 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 7976 | } |
| 7977 | } |
| 7978 | } finally { |
| 7979 | Binder.restoreCallingIdentity(identity); |
| 7980 | } |
| 7981 | } |
| 7982 | |
| 7983 | @Override |
| 7984 | public void resetOtaEmergencyNumberDbFilePath() { |
| 7985 | enforceActiveEmergencySessionPermission(); |
| 7986 | |
| 7987 | final long identity = Binder.clearCallingIdentity(); |
| 7988 | try { |
| 7989 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7990 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7991 | if (tracker != null) { |
| 7992 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7993 | } |
| 7994 | } |
| 7995 | } finally { |
| 7996 | Binder.restoreCallingIdentity(identity); |
| 7997 | } |
| 7998 | } |
| 7999 | |
| 8000 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8001 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8002 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8003 | Phone phone = getPhone(subId); |
| 8004 | if (phone == null) { |
| 8005 | return null; |
| 8006 | } |
| 8007 | final long identity = Binder.clearCallingIdentity(); |
| 8008 | try { |
| 8009 | UiccProfile profile = UiccController.getInstance() |
| 8010 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8011 | if (profile != null) { |
| 8012 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8013 | } |
| 8014 | } finally { |
| 8015 | Binder.restoreCallingIdentity(identity); |
| 8016 | } |
| 8017 | return null; |
| 8018 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8019 | |
| 8020 | /** |
| 8021 | * Enable or disable a modem stack. |
| 8022 | */ |
| 8023 | @Override |
| 8024 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8025 | enforceModifyPermission(); |
| 8026 | |
| 8027 | final long identity = Binder.clearCallingIdentity(); |
| 8028 | try { |
| 8029 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8030 | if (phone == null) { |
| 8031 | return false; |
| 8032 | } else { |
| 8033 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8034 | } |
| 8035 | } finally { |
| 8036 | Binder.restoreCallingIdentity(identity); |
| 8037 | } |
| 8038 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8039 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8040 | /** |
| 8041 | * Whether a modem stack is enabled or not. |
| 8042 | */ |
| 8043 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8044 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8045 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8046 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8047 | if (phone == null) return false; |
| 8048 | |
| 8049 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8050 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8051 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8052 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8053 | } |
| 8054 | |
| 8055 | final long identity = Binder.clearCallingIdentity(); |
| 8056 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8057 | try { |
| 8058 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8059 | } catch (NoSuchElementException ex) { |
| 8060 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8061 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8062 | } finally { |
| 8063 | Binder.restoreCallingIdentity(identity); |
| 8064 | } |
| 8065 | } |
| 8066 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8067 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8068 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8069 | enforceModifyPermission(); |
| 8070 | |
| 8071 | final long identity = Binder.clearCallingIdentity(); |
| 8072 | try { |
| 8073 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8074 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8075 | .commit(); |
| 8076 | } finally { |
| 8077 | Binder.restoreCallingIdentity(identity); |
| 8078 | } |
| 8079 | } |
| 8080 | |
| 8081 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8082 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8083 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8084 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8085 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8086 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8087 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8088 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8089 | |
| 8090 | final long identity = Binder.clearCallingIdentity(); |
| 8091 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8092 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8093 | } finally { |
| 8094 | Binder.restoreCallingIdentity(identity); |
| 8095 | } |
| 8096 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8097 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8098 | @TelephonyManager.IsMultiSimSupportedResult |
| 8099 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8100 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8101 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8102 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8103 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8104 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8105 | } |
| 8106 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8107 | // supported by the modem, indicate that it is restricted. |
| 8108 | PhoneCapability staticCapability = |
| 8109 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8110 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8111 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8112 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8113 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8114 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8115 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8116 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8117 | } |
| 8118 | // Check if support of multiple SIMs is restricted by carrier |
| 8119 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8120 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8121 | } |
| 8122 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8123 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8124 | } |
| 8125 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8126 | /** |
| 8127 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8128 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8129 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8130 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8131 | * @param numOfSims number of active sims we want to switch to |
| 8132 | */ |
| 8133 | @Override |
| 8134 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8135 | if (numOfSims == 1) { |
| 8136 | enforceModifyPermission(); |
| 8137 | } else { |
| 8138 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8139 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8140 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8141 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8142 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8143 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8144 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8145 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8146 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8147 | return; |
| 8148 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8149 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8150 | } finally { |
| 8151 | Binder.restoreCallingIdentity(identity); |
| 8152 | } |
| 8153 | } |
| 8154 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8155 | @Override |
| 8156 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8157 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8158 | Phone phone = getPhone(subId); |
| 8159 | if (phone == null) { |
| 8160 | return false; |
| 8161 | } |
| 8162 | final long identity = Binder.clearCallingIdentity(); |
| 8163 | try { |
| 8164 | UiccCard uiccCard = phone.getUiccCard(); |
| 8165 | if (uiccCard == null) { |
| 8166 | return false; |
| 8167 | } |
| 8168 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8169 | if (uiccProfile == null) { |
| 8170 | return false; |
| 8171 | } |
| 8172 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8173 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8174 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8175 | } |
| 8176 | return false; |
| 8177 | } finally { |
| 8178 | Binder.restoreCallingIdentity(identity); |
| 8179 | } |
| 8180 | } |
| 8181 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8182 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8183 | * Get whether making changes to modem configurations will trigger reboot. |
| 8184 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8185 | */ |
| 8186 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8187 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8188 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8189 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8190 | mApp, subId, callingPackage, callingFeatureId, |
| 8191 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8192 | return false; |
| 8193 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8194 | final long identity = Binder.clearCallingIdentity(); |
| 8195 | try { |
| 8196 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8197 | } finally { |
| 8198 | Binder.restoreCallingIdentity(identity); |
| 8199 | } |
| 8200 | } |
| 8201 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8202 | private void updateModemStateMetrics() { |
| 8203 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8204 | // TODO: check the state for each modem if the api is ready. |
| 8205 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8206 | } |
| 8207 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8208 | @Override |
| 8209 | public int[] getSlotsMapping() { |
| 8210 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8211 | |
| 8212 | final long identity = Binder.clearCallingIdentity(); |
| 8213 | try { |
| 8214 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8215 | // All logical slots should have a mapping to a physical slot. |
| 8216 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8217 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8218 | for (int i = 0; i < slotInfos.length; i++) { |
| 8219 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8220 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8221 | } |
| 8222 | } |
| 8223 | return logicalSlotsMapping; |
| 8224 | } finally { |
| 8225 | Binder.restoreCallingIdentity(identity); |
| 8226 | } |
| 8227 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8228 | |
| 8229 | /** |
| 8230 | * Get the IRadio HAL Version |
| 8231 | */ |
| 8232 | @Override |
| 8233 | public int getRadioHalVersion() { |
| 8234 | Phone phone = getDefaultPhone(); |
| 8235 | if (phone == null) return -1; |
| 8236 | HalVersion hv = phone.getHalVersion(); |
| 8237 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8238 | return hv.major * 100 + hv.minor; |
| 8239 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8240 | |
| 8241 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8242 | * Get the current calling package name. |
| 8243 | * @return the current calling package name |
| 8244 | */ |
| 8245 | @Override |
| 8246 | public String getCurrentPackageName() { |
| 8247 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8248 | } |
| 8249 | |
| 8250 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8251 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8252 | * corresponding network requests on a subId. |
| 8253 | * |
| 8254 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8255 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8256 | * 2) APN is un-metered for this subscription, or |
| 8257 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8258 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8259 | * |
| 8260 | * @return whether data is allowed for a apn type. |
| 8261 | * |
| 8262 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8263 | */ |
| 8264 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8265 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8266 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8267 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8268 | |
| 8269 | // Now that all security checks passes, perform the operation as ourselves. |
| 8270 | final long identity = Binder.clearCallingIdentity(); |
| 8271 | try { |
| 8272 | Phone phone = getPhone(subId); |
| 8273 | if (phone == null) return false; |
| 8274 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8275 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8276 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8277 | } finally { |
| 8278 | Binder.restoreCallingIdentity(identity); |
| 8279 | } |
| 8280 | } |
| 8281 | |
| 8282 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8283 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8284 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8285 | |
| 8286 | // Now that all security checks passes, perform the operation as ourselves. |
| 8287 | final long identity = Binder.clearCallingIdentity(); |
| 8288 | try { |
| 8289 | Phone phone = getPhone(subId); |
| 8290 | if (phone == null) return true; // By default return true. |
| 8291 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8292 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8293 | } finally { |
| 8294 | Binder.restoreCallingIdentity(identity); |
| 8295 | } |
| 8296 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8297 | |
| 8298 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8299 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8300 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8301 | enforceModifyPermission(); |
| 8302 | long token = Binder.clearCallingIdentity(); |
| 8303 | try { |
| 8304 | Phone phone = getPhone(subscriptionId); |
| 8305 | if (phone == null) { |
| 8306 | try { |
| 8307 | if (resultCallback != null) { |
| 8308 | resultCallback.accept(false); |
| 8309 | } |
| 8310 | } catch (RemoteException e) { |
| 8311 | // ignore |
| 8312 | } |
| 8313 | return; |
| 8314 | } |
| 8315 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8316 | Pair.create(specifiers, (x) -> { |
| 8317 | try { |
| 8318 | if (resultCallback != null) { |
| 8319 | resultCallback.accept(x); |
| 8320 | } |
| 8321 | } catch (RemoteException e) { |
| 8322 | // ignore |
| 8323 | } |
| 8324 | }); |
| 8325 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8326 | } finally { |
| 8327 | Binder.restoreCallingIdentity(token); |
| 8328 | } |
| 8329 | } |
| 8330 | |
| 8331 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8332 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8333 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8334 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8335 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8336 | if (iccRecords == null) { |
| 8337 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8338 | return false; |
| 8339 | } |
| 8340 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8341 | } |
| 8342 | |
| 8343 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8344 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8345 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8346 | if (callingPackage == null) { |
| 8347 | callingPackage = getCurrentPackageName(); |
| 8348 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8349 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8350 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8351 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8352 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8353 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8354 | } |
| 8355 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8356 | Intent intent = new Intent(); |
| 8357 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8358 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8359 | // Bring up choose default SMS subscription dialog right now |
| 8360 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8361 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8362 | mApp.startActivity(intent); |
| 8363 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8364 | |
| 8365 | @Override |
| 8366 | public String getMmsUAProfUrl(int subId) { |
| 8367 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8368 | final long identity = Binder.clearCallingIdentity(); |
| 8369 | try { |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8370 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8371 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8372 | } finally { |
| 8373 | Binder.restoreCallingIdentity(identity); |
| 8374 | } |
| 8375 | } |
| 8376 | |
| 8377 | @Override |
| 8378 | public String getMmsUserAgent(int subId) { |
| 8379 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8380 | final long identity = Binder.clearCallingIdentity(); |
| 8381 | try { |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8382 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8383 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8384 | } finally { |
| 8385 | Binder.restoreCallingIdentity(identity); |
| 8386 | } |
| 8387 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8388 | |
| 8389 | @Override |
| 8390 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8391 | enforceModifyPermission(); |
| 8392 | |
| 8393 | // Now that all security checks passes, perform the operation as ourselves. |
| 8394 | final long identity = Binder.clearCallingIdentity(); |
| 8395 | try { |
| 8396 | Phone phone = getPhone(subId); |
| 8397 | if (phone == null) return false; |
| 8398 | |
| 8399 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8400 | } finally { |
| 8401 | Binder.restoreCallingIdentity(identity); |
| 8402 | } |
| 8403 | } |
| 8404 | |
| 8405 | @Override |
| 8406 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8407 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8408 | |
| 8409 | // Now that all security checks passes, perform the operation as ourselves. |
| 8410 | final long identity = Binder.clearCallingIdentity(); |
| 8411 | try { |
| 8412 | Phone phone = getPhone(subId); |
| 8413 | if (phone == null) return false; |
| 8414 | |
| 8415 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8416 | } finally { |
| 8417 | Binder.restoreCallingIdentity(identity); |
| 8418 | } |
| 8419 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8420 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8421 | @Override |
| 8422 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8423 | enforceModifyPermission(); |
| 8424 | |
| 8425 | // Now that all security checks passes, perform the operation as ourselves. |
| 8426 | final long identity = Binder.clearCallingIdentity(); |
| 8427 | try { |
| 8428 | Phone phone = getPhone(subId); |
| 8429 | if (phone == null) return false; |
| 8430 | |
| 8431 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8432 | } finally { |
| 8433 | Binder.restoreCallingIdentity(identity); |
| 8434 | } |
| 8435 | } |
| 8436 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8437 | /** |
| 8438 | * Updates whether conference event pacakge handling is enabled. |
| 8439 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8440 | * otherwise. |
| 8441 | */ |
| 8442 | @Override |
| 8443 | public void setCepEnabled(boolean isCepEnabled) { |
| 8444 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8445 | |
| 8446 | final long identity = Binder.clearCallingIdentity(); |
| 8447 | try { |
| 8448 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8449 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8450 | Phone defaultPhone = phone.getImsPhone(); |
| 8451 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8452 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8453 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8454 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8455 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8456 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8457 | + imsPhone.getMsisdn()); |
| 8458 | } |
| 8459 | } |
| 8460 | } finally { |
| 8461 | Binder.restoreCallingIdentity(identity); |
| 8462 | } |
| 8463 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8464 | |
| 8465 | /** |
| 8466 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8467 | * |
| 8468 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8469 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8470 | * before being read. |
| 8471 | */ |
| 8472 | @Override |
| 8473 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8474 | isCompressed) { |
| 8475 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8476 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8477 | try { |
| 8478 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8479 | if (configBinder == null) { |
| 8480 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8481 | } else { |
| 8482 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8483 | } |
| 8484 | } catch (RemoteException e) { |
| 8485 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8486 | } |
| 8487 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8488 | |
| 8489 | @Override |
| 8490 | public boolean isIccLockEnabled(int subId) { |
| 8491 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8492 | |
| 8493 | // Now that all security checks passes, perform the operation as ourselves. |
| 8494 | final long identity = Binder.clearCallingIdentity(); |
| 8495 | try { |
| 8496 | Phone phone = getPhone(subId); |
| 8497 | if (phone != null && phone.getIccCard() != null) { |
| 8498 | return phone.getIccCard().getIccLockEnabled(); |
| 8499 | } else { |
| 8500 | return false; |
| 8501 | } |
| 8502 | } finally { |
| 8503 | Binder.restoreCallingIdentity(identity); |
| 8504 | } |
| 8505 | } |
| 8506 | |
| 8507 | /** |
| 8508 | * Set the ICC pin lock enabled or disabled. |
| 8509 | * |
| 8510 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8511 | * three cases: |
| 8512 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8513 | * successfully. |
| 8514 | * - Positive number and zero for remaining password attempts. |
| 8515 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8516 | * |
| 8517 | */ |
| 8518 | @Override |
| 8519 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8520 | enforceModifyPermission(); |
| 8521 | |
| 8522 | Phone phone = getPhone(subId); |
| 8523 | if (phone == null) { |
| 8524 | return 0; |
| 8525 | } |
| 8526 | // Now that all security checks passes, perform the operation as ourselves. |
| 8527 | final long identity = Binder.clearCallingIdentity(); |
| 8528 | try { |
| 8529 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8530 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8531 | return attemptsRemaining; |
| 8532 | |
| 8533 | } catch (Exception e) { |
| 8534 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8535 | } finally { |
| 8536 | Binder.restoreCallingIdentity(identity); |
| 8537 | } |
| 8538 | return 0; |
| 8539 | } |
| 8540 | |
| 8541 | /** |
| 8542 | * Change the ICC password used in ICC pin lock. |
| 8543 | * |
| 8544 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8545 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8546 | * - Positive number and zero for remaining password attempts. |
| 8547 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8548 | * |
| 8549 | */ |
| 8550 | @Override |
| 8551 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8552 | enforceModifyPermission(); |
| 8553 | |
| 8554 | Phone phone = getPhone(subId); |
| 8555 | if (phone == null) { |
| 8556 | return 0; |
| 8557 | } |
| 8558 | // Now that all security checks passes, perform the operation as ourselves. |
| 8559 | final long identity = Binder.clearCallingIdentity(); |
| 8560 | try { |
| 8561 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8562 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8563 | return attemptsRemaining; |
| 8564 | |
| 8565 | } catch (Exception e) { |
| 8566 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8567 | } finally { |
| 8568 | Binder.restoreCallingIdentity(identity); |
| 8569 | } |
| 8570 | return 0; |
| 8571 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8572 | |
| 8573 | /** |
| 8574 | * Request for receiving user activity notification |
| 8575 | */ |
| 8576 | @Override |
| 8577 | public void requestUserActivityNotification() { |
| 8578 | if (!mNotifyUserActivity.get() |
| 8579 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8580 | mNotifyUserActivity.set(true); |
| 8581 | } |
| 8582 | } |
| 8583 | |
| 8584 | /** |
| 8585 | * Called when userActivity is signalled in the power manager. |
| 8586 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8587 | */ |
| 8588 | @Override |
| 8589 | public void userActivity() { |
| 8590 | // *************************************** |
| 8591 | // * Inherited from PhoneWindowManager * |
| 8592 | // *************************************** |
| 8593 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8594 | // WITH ITS LOCKS HELD. |
| 8595 | // |
| 8596 | // This code must be VERY careful about the locks |
| 8597 | // it acquires. |
| 8598 | // In fact, the current code acquires way too many, |
| 8599 | // and probably has lurking deadlocks. |
| 8600 | |
| 8601 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8602 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8603 | } |
| 8604 | |
| 8605 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8606 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8607 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8608 | } |
| 8609 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8610 | |
| 8611 | @Override |
| 8612 | public boolean canConnectTo5GInDsdsMode() { |
| 8613 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 8614 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8615 | } |