Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 69 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 70 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 71 | import android.telephony.CellIdentityCdma; |
| 72 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfoGsm; |
| 75 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 76 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 77 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 78 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 79 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 80 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 81 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 82 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 83 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 85 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 88 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Jordan Liu | 102b277 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 123 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 161 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 173 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 175 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 176 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 178 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 180 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 181 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 182 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 183 | import java.io.FileDescriptor; |
| 184 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 186 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 187 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 190 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 191 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 192 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 193 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 194 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 195 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * Implementation of the ITelephony interface. |
| 199 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 200 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 202 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 203 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 204 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | |
| 206 | // Message codes used with mMainThreadHandler |
| 207 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 208 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 209 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 210 | private static final int CMD_OPEN_CHANNEL = 9; |
| 211 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 212 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 213 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 214 | private static final int CMD_NV_READ_ITEM = 13; |
| 215 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 216 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 217 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 218 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 219 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 220 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 221 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 222 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 223 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 224 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 225 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 226 | private static final int CMD_SEND_ENVELOPE = 25; |
| 227 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 228 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 229 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 230 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 231 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 232 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 233 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 234 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 235 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 236 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 237 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 238 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 239 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 240 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 241 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 242 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 243 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 244 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 245 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 246 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 247 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 248 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 249 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 250 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 251 | private static final int CMD_SWITCH_SLOTS = 50; |
| 252 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 253 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 254 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 255 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 256 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 257 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 258 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 259 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 260 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 261 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 262 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 263 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 264 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 265 | private static final int CMD_MODEM_REBOOT = 64; |
| 266 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 267 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 268 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 269 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 270 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 271 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 272 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 273 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 274 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 275 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 276 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 277 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 278 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 279 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 280 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 281 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 282 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 283 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 284 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 285 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 286 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 287 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 288 | private static final int CMD_GET_CALL_WAITING = 87; |
| 289 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 290 | private static final int CMD_SET_CALL_WAITING = 89; |
| 291 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 292 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 293 | // Parameters of select command. |
| 294 | private static final int SELECT_COMMAND = 0xA4; |
| 295 | private static final int SELECT_P1 = 0x04; |
| 296 | private static final int SELECT_P2 = 0; |
| 297 | private static final int SELECT_P3 = 0x10; |
| 298 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 299 | /** The singleton instance. */ |
| 300 | private static PhoneInterfaceManager sInstance; |
| 301 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 302 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 303 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 304 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 305 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 306 | private AppOpsManager mAppOps; |
| 307 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 308 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 309 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 310 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 311 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 312 | /** User Activity */ |
| 313 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 314 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 315 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 316 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 317 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 318 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 319 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 320 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 321 | // String to store multi SIM allowed |
| 322 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 323 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 324 | // The AID of ISD-R. |
| 325 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 326 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 327 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 328 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 329 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 330 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 331 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 332 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 333 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 334 | */ |
| 335 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 336 | "reset_network_erase_modem_config_enabled"; |
| 337 | |
| 338 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 339 | * A request object to use for transmitting data to an ICC. |
| 340 | */ |
| 341 | private static final class IccAPDUArgument { |
| 342 | public int channel, cla, command, p1, p2, p3; |
| 343 | public String data; |
| 344 | |
| 345 | public IccAPDUArgument(int channel, int cla, int command, |
| 346 | int p1, int p2, int p3, String data) { |
| 347 | this.channel = channel; |
| 348 | this.cla = cla; |
| 349 | this.command = command; |
| 350 | this.p1 = p1; |
| 351 | this.p2 = p2; |
| 352 | this.p3 = p3; |
| 353 | this.data = data; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 358 | * A request object to use for transmitting data to an ICC. |
| 359 | */ |
| 360 | private static final class ManualNetworkSelectionArgument { |
| 361 | public OperatorInfo operatorInfo; |
| 362 | public boolean persistSelection; |
| 363 | |
| 364 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 365 | this.operatorInfo = operatorInfo; |
| 366 | this.persistSelection = persistSelection; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 372 | * request after sending. The main thread will notify the request when it is complete. |
| 373 | */ |
| 374 | private static final class MainThreadRequest { |
| 375 | /** The argument to use for the request */ |
| 376 | public Object argument; |
| 377 | /** The result of the request that is run on the main thread */ |
| 378 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 379 | // The subscriber id that this request applies to. Defaults to |
| 380 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 381 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 383 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 384 | public Phone phone; |
| 385 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 386 | public WorkSource workSource; |
| 387 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 388 | public MainThreadRequest(Object argument) { |
| 389 | this.argument = argument; |
| 390 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 391 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 392 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 393 | this.argument = argument; |
| 394 | if (phone != null) { |
| 395 | this.phone = phone; |
| 396 | } |
| 397 | this.workSource = workSource; |
| 398 | } |
| 399 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 400 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 401 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 402 | if (subId != null) { |
| 403 | this.subId = subId; |
| 404 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 405 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 409 | private static final class IncomingThirdPartyCallArgs { |
| 410 | public final ComponentName component; |
| 411 | public final String callId; |
| 412 | public final String callerDisplayName; |
| 413 | |
| 414 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 415 | String callerDisplayName) { |
| 416 | this.component = component; |
| 417 | this.callId = callId; |
| 418 | this.callerDisplayName = callerDisplayName; |
| 419 | } |
| 420 | } |
| 421 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 422 | /** |
| 423 | * A handler that processes messages on the main thread in the phone process. Since many |
| 424 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 425 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 426 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 427 | * on, which will be notified when the operation completes and will contain the result of the |
| 428 | * request. |
| 429 | * |
| 430 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 431 | * note that request.result must be set to something non-null for the calling thread to |
| 432 | * unblock. |
| 433 | */ |
| 434 | private final class MainThreadHandler extends Handler { |
| 435 | @Override |
| 436 | public void handleMessage(Message msg) { |
| 437 | MainThreadRequest request; |
| 438 | Message onCompleted; |
| 439 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 440 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 441 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 442 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 443 | |
| 444 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 445 | case CMD_HANDLE_USSD_REQUEST: { |
| 446 | request = (MainThreadRequest) msg.obj; |
| 447 | final Phone phone = getPhoneFromRequest(request); |
| 448 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 449 | String ussdRequest = ussdObject.first; |
| 450 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 451 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 452 | if (!isUssdApiAllowed(request.subId)) { |
| 453 | // Carrier does not support use of this API, return failure. |
| 454 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 455 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 456 | Bundle returnData = new Bundle(); |
| 457 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 458 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 459 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 460 | request.result = true; |
| 461 | notifyRequester(request); |
| 462 | return; |
| 463 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 464 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 465 | try { |
| 466 | request.result = phone != null |
| 467 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 468 | } catch (CallStateException cse) { |
| 469 | request.result = false; |
| 470 | } |
| 471 | // Wake up the requesting thread |
| 472 | notifyRequester(request); |
| 473 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 476 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 478 | final Phone phone = getPhoneFromRequest(request); |
| 479 | request.result = phone != null ? |
| 480 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 481 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 482 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 483 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 484 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 487 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 488 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 490 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 491 | if (uiccCard == null) { |
| 492 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 493 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 494 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 495 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 497 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 498 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 499 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 500 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 501 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 502 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | break; |
| 504 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 505 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 506 | ar = (AsyncResult) msg.obj; |
| 507 | request = (MainThreadRequest) ar.userObj; |
| 508 | if (ar.exception == null && ar.result != null) { |
| 509 | request.result = ar.result; |
| 510 | } else { |
| 511 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 512 | if (ar.result == null) { |
| 513 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 514 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 515 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 516 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 517 | } else { |
| 518 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 519 | } |
| 520 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 522 | break; |
| 523 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 524 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 525 | request = (MainThreadRequest) msg.obj; |
| 526 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 527 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | if (uiccCard == null) { |
| 529 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 530 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | } else { |
| 533 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 534 | request); |
| 535 | uiccCard.iccTransmitApduBasicChannel( |
| 536 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 537 | iccArgument.p3, iccArgument.data, onCompleted); |
| 538 | } |
| 539 | break; |
| 540 | |
| 541 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 542 | ar = (AsyncResult) msg.obj; |
| 543 | request = (MainThreadRequest) ar.userObj; |
| 544 | if (ar.exception == null && ar.result != null) { |
| 545 | request.result = ar.result; |
| 546 | } else { |
| 547 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 548 | if (ar.result == null) { |
| 549 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 550 | } else if (ar.exception instanceof CommandException) { |
| 551 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 552 | ar.exception); |
| 553 | } else { |
| 554 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 555 | } |
| 556 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 557 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 558 | break; |
| 559 | |
| 560 | case CMD_EXCHANGE_SIM_IO: |
| 561 | request = (MainThreadRequest) msg.obj; |
| 562 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 563 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 564 | if (uiccCard == null) { |
| 565 | loge("iccExchangeSimIO: No UICC"); |
| 566 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 567 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 568 | } else { |
| 569 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 570 | request); |
| 571 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 572 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 573 | iccArgument.data, onCompleted); |
| 574 | } |
| 575 | break; |
| 576 | |
| 577 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 578 | ar = (AsyncResult) msg.obj; |
| 579 | request = (MainThreadRequest) ar.userObj; |
| 580 | if (ar.exception == null && ar.result != null) { |
| 581 | request.result = ar.result; |
| 582 | } else { |
| 583 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 584 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | break; |
| 587 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 588 | case CMD_SEND_ENVELOPE: |
| 589 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 590 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 591 | if (uiccCard == null) { |
| 592 | loge("sendEnvelopeWithStatus: No UICC"); |
| 593 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 594 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 595 | } else { |
| 596 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 597 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 598 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 599 | break; |
| 600 | |
| 601 | case EVENT_SEND_ENVELOPE_DONE: |
| 602 | ar = (AsyncResult) msg.obj; |
| 603 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 604 | if (ar.exception == null && ar.result != null) { |
| 605 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 606 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 607 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 608 | if (ar.result == null) { |
| 609 | loge("sendEnvelopeWithStatus: Empty response"); |
| 610 | } else if (ar.exception instanceof CommandException) { |
| 611 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 612 | ar.exception); |
| 613 | } else { |
| 614 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 615 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 616 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 618 | break; |
| 619 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | case CMD_OPEN_CHANNEL: |
| 621 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 622 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 623 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | if (uiccCard == null) { |
| 625 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 626 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 627 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 629 | } else { |
| 630 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 631 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 632 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 633 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | break; |
| 635 | |
| 636 | case EVENT_OPEN_CHANNEL_DONE: |
| 637 | ar = (AsyncResult) msg.obj; |
| 638 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 641 | int[] result = (int[]) ar.result; |
| 642 | int channelId = result[0]; |
| 643 | byte[] selectResponse = null; |
| 644 | if (result.length > 1) { |
| 645 | selectResponse = new byte[result.length - 1]; |
| 646 | for (int i = 1; i < result.length; ++i) { |
| 647 | selectResponse[i - 1] = (byte) result[i]; |
| 648 | } |
| 649 | } |
| 650 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 651 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 653 | if (ar.result == null) { |
| 654 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | if (ar.exception != null) { |
| 657 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 658 | } |
| 659 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 660 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 661 | if (ar.exception instanceof CommandException) { |
| 662 | CommandException.Error error = |
| 663 | ((CommandException) (ar.exception)).getCommandError(); |
| 664 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 665 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 666 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 667 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 671 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 673 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 674 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | break; |
| 676 | |
| 677 | case CMD_CLOSE_CHANNEL: |
| 678 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 679 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 680 | if (uiccCard == null) { |
| 681 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 682 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 683 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 684 | } else { |
| 685 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 686 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 687 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 692 | break; |
| 693 | |
| 694 | case CMD_NV_READ_ITEM: |
| 695 | request = (MainThreadRequest) msg.obj; |
| 696 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 697 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 698 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 699 | break; |
| 700 | |
| 701 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | ar = (AsyncResult) msg.obj; |
| 703 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 704 | if (ar.exception == null && ar.result != null) { |
| 705 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 707 | request.result = ""; |
| 708 | if (ar.result == null) { |
| 709 | loge("nvReadItem: Empty response"); |
| 710 | } else if (ar.exception instanceof CommandException) { |
| 711 | loge("nvReadItem: CommandException: " + |
| 712 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 713 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 718 | break; |
| 719 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 720 | case CMD_NV_WRITE_ITEM: |
| 721 | request = (MainThreadRequest) msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 723 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 724 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 725 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case EVENT_NV_WRITE_ITEM_DONE: |
| 729 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 730 | break; |
| 731 | |
| 732 | case CMD_NV_WRITE_CDMA_PRL: |
| 733 | request = (MainThreadRequest) msg.obj; |
| 734 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 735 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 739 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 740 | break; |
| 741 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 742 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 744 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 745 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 748 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 749 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 750 | break; |
| 751 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 752 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 753 | request = (MainThreadRequest) msg.obj; |
| 754 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 755 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 759 | ar = (AsyncResult) msg.obj; |
| 760 | request = (MainThreadRequest) ar.userObj; |
| 761 | if (ar.exception == null && ar.result != null) { |
| 762 | request.result = ar.result; // Integer |
| 763 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 764 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 765 | if (ar.result == null) { |
| 766 | loge("getPreferredNetworkType: Empty response"); |
| 767 | } else if (ar.exception instanceof CommandException) { |
| 768 | loge("getPreferredNetworkType: CommandException: " + |
| 769 | ar.exception); |
| 770 | } else { |
| 771 | loge("getPreferredNetworkType: Unknown exception"); |
| 772 | } |
| 773 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 774 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 778 | request = (MainThreadRequest) msg.obj; |
| 779 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 780 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 781 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 785 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 786 | break; |
| 787 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 788 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 789 | request = (MainThreadRequest)msg.obj; |
| 790 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 791 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 792 | break; |
| 793 | |
| 794 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 795 | ar = (AsyncResult)msg.obj; |
| 796 | request = (MainThreadRequest)ar.userObj; |
| 797 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 798 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 799 | break; |
| 800 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 801 | case CMD_SET_VOICEMAIL_NUMBER: |
| 802 | request = (MainThreadRequest) msg.obj; |
| 803 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 804 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 805 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 806 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 807 | break; |
| 808 | |
| 809 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 810 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 811 | break; |
| 812 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 813 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 814 | request = (MainThreadRequest) msg.obj; |
| 815 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 816 | request); |
| 817 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 818 | break; |
| 819 | |
| 820 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 821 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 822 | break; |
| 823 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 824 | case CMD_PERFORM_NETWORK_SCAN: |
| 825 | request = (MainThreadRequest) msg.obj; |
| 826 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 827 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 828 | break; |
| 829 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 830 | case CMD_GET_CALL_FORWARDING: |
| 831 | request = (MainThreadRequest) msg.obj; |
| 832 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 833 | int callForwardingReason = (Integer) request.argument; |
| 834 | getPhoneFromRequest(request).getCallForwardingOption( |
| 835 | callForwardingReason, onCompleted); |
| 836 | break; |
| 837 | |
| 838 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 839 | ar = (AsyncResult) msg.obj; |
| 840 | request = (MainThreadRequest) ar.userObj; |
| 841 | CallForwardingInfo callForwardingInfo = null; |
| 842 | if (ar.exception == null && ar.result != null) { |
| 843 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 844 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 845 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 846 | // any service for voice call. |
| 847 | if ((callForwardInfo.serviceClass |
| 848 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 849 | callForwardingInfo = new CallForwardingInfo( |
| 850 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 851 | callForwardInfo.number, |
| 852 | callForwardInfo.timeSeconds); |
| 853 | break; |
| 854 | } |
| 855 | } |
| 856 | // Didn't find a call forward info for voice call. |
| 857 | if (callForwardingInfo == null) { |
| 858 | callForwardingInfo = new CallForwardingInfo( |
| 859 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 860 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 861 | } |
| 862 | } else { |
| 863 | if (ar.result == null) { |
| 864 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 865 | } |
| 866 | if (ar.exception != null) { |
| 867 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 868 | } |
| 869 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 870 | if (ar.exception instanceof CommandException) { |
| 871 | CommandException.Error error = |
| 872 | ((CommandException) (ar.exception)).getCommandError(); |
| 873 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 874 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 875 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 876 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 877 | } |
| 878 | } |
| 879 | callForwardingInfo = new CallForwardingInfo( |
| 880 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 881 | } |
| 882 | request.result = callForwardingInfo; |
| 883 | notifyRequester(request); |
| 884 | break; |
| 885 | |
| 886 | case CMD_SET_CALL_FORWARDING: |
| 887 | request = (MainThreadRequest) msg.obj; |
| 888 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 889 | CallForwardingInfo callForwardingInfoToSet = |
| 890 | (CallForwardingInfo) request.argument; |
| 891 | getPhoneFromRequest(request).setCallForwardingOption( |
| 892 | callForwardingInfoToSet.getStatus(), |
| 893 | callForwardingInfoToSet.getReason(), |
| 894 | callForwardingInfoToSet.getNumber(), |
| 895 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 896 | break; |
| 897 | |
| 898 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 899 | ar = (AsyncResult) msg.obj; |
| 900 | request = (MainThreadRequest) ar.userObj; |
| 901 | if (ar.exception == null) { |
| 902 | request.result = true; |
| 903 | } else { |
| 904 | request.result = false; |
| 905 | loge("setCallForwarding exception: " + ar.exception); |
| 906 | } |
| 907 | notifyRequester(request); |
| 908 | break; |
| 909 | |
| 910 | case CMD_GET_CALL_WAITING: |
| 911 | request = (MainThreadRequest) msg.obj; |
| 912 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 913 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 914 | break; |
| 915 | |
| 916 | case EVENT_GET_CALL_WAITING_DONE: |
| 917 | ar = (AsyncResult) msg.obj; |
| 918 | request = (MainThreadRequest) ar.userObj; |
| 919 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 920 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 921 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 922 | // Service Class is a bit mask per 3gpp 27.007. |
| 923 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 924 | if (callForwardResults.length > 1 |
| 925 | && ((callForwardResults[1] |
| 926 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 927 | callForwardingStatus = callForwardResults[0] == 0 |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 928 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 929 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 930 | } else { |
| 931 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 932 | } |
| 933 | } else { |
| 934 | if (ar.result == null) { |
| 935 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 936 | } |
| 937 | if (ar.exception != null) { |
| 938 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 939 | } |
| 940 | if (ar.exception instanceof CommandException) { |
| 941 | CommandException.Error error = |
| 942 | ((CommandException) (ar.exception)).getCommandError(); |
| 943 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 944 | callForwardingStatus = |
| 945 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | request.result = callForwardingStatus; |
| 950 | notifyRequester(request); |
| 951 | break; |
| 952 | |
| 953 | case CMD_SET_CALL_WAITING: |
| 954 | request = (MainThreadRequest) msg.obj; |
| 955 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 956 | boolean isEnable = (Boolean) request.argument; |
| 957 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 958 | break; |
| 959 | |
| 960 | case EVENT_SET_CALL_WAITING_DONE: |
| 961 | ar = (AsyncResult) msg.obj; |
| 962 | request = (MainThreadRequest) ar.userObj; |
| 963 | if (ar.exception == null) { |
| 964 | request.result = true; |
| 965 | } else { |
| 966 | request.result = false; |
| 967 | loge("setCallWaiting exception: " + ar.exception); |
| 968 | } |
| 969 | notifyRequester(request); |
| 970 | break; |
| 971 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 972 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 973 | ar = (AsyncResult) msg.obj; |
| 974 | request = (MainThreadRequest) ar.userObj; |
| 975 | CellNetworkScanResult cellScanResult; |
| 976 | if (ar.exception == null && ar.result != null) { |
| 977 | cellScanResult = new CellNetworkScanResult( |
| 978 | CellNetworkScanResult.STATUS_SUCCESS, |
| 979 | (List<OperatorInfo>) ar.result); |
| 980 | } else { |
| 981 | if (ar.result == null) { |
| 982 | loge("getCellNetworkScanResults: Empty response"); |
| 983 | } |
| 984 | if (ar.exception != null) { |
| 985 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 986 | } |
| 987 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 988 | if (ar.exception instanceof CommandException) { |
| 989 | CommandException.Error error = |
| 990 | ((CommandException) (ar.exception)).getCommandError(); |
| 991 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 992 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 993 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 994 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 995 | } |
| 996 | } |
| 997 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 998 | } |
| 999 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1000 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1001 | break; |
| 1002 | |
| 1003 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1004 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1005 | ManualNetworkSelectionArgument selArg = |
| 1006 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1007 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1008 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1009 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1010 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1011 | break; |
| 1012 | |
| 1013 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1014 | ar = (AsyncResult) msg.obj; |
| 1015 | request = (MainThreadRequest) ar.userObj; |
| 1016 | if (ar.exception == null) { |
| 1017 | request.result = true; |
| 1018 | } else { |
| 1019 | request.result = false; |
| 1020 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1021 | } |
| 1022 | notifyRequester(request); |
| 1023 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1024 | break; |
| 1025 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1026 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1027 | request = (MainThreadRequest) msg.obj; |
| 1028 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1029 | if (defaultPhone != null) { |
| 1030 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 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 | 8f4750a | 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 | 8f4750a | 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 | 8f4750a | 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 | 102b277 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 1653 | @VisibleForTesting |
| 1654 | /* package */ PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1655 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1656 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1657 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1658 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1659 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1660 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1661 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1662 | mTelephonySharedPreferences = |
| 1663 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1664 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1665 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1666 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1667 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1668 | publish(); |
| 1669 | } |
| 1670 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1671 | private Phone getDefaultPhone() { |
| 1672 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1673 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1674 | } |
| 1675 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1676 | private void publish() { |
| 1677 | if (DBG) log("publish: " + this); |
| 1678 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1679 | TelephonyFrameworkInitializer |
| 1680 | .getTelephonyServiceManager() |
| 1681 | .getTelephonyServiceRegisterer() |
| 1682 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1685 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1686 | if (request.phone != null) { |
| 1687 | return request.phone; |
| 1688 | } else { |
| 1689 | return getPhoneFromSubId(request.subId); |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | private Phone getPhoneFromSubId(int subId) { |
| 1694 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1695 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1696 | } |
| 1697 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1698 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1699 | Phone phone = getPhoneFromRequest(request); |
| 1700 | return phone == null ? null : |
| 1701 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1702 | } |
| 1703 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1704 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1705 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1706 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1707 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1708 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1709 | private void sendEraseModemConfig(Phone phone) { |
| 1710 | if (phone != null) { |
| 1711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1712 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1713 | final long identity = Binder.clearCallingIdentity(); |
| 1714 | try { |
| 1715 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1716 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1717 | } finally { |
| 1718 | Binder.restoreCallingIdentity(identity); |
| 1719 | } |
| 1720 | } |
| 1721 | } |
| 1722 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1723 | private boolean isImsAvailableOnDevice() { |
| 1724 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1725 | if (pm == null) { |
| 1726 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1727 | // so do not throw error and allow. |
| 1728 | return true; |
| 1729 | } |
| 1730 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1731 | } |
| 1732 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1733 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1734 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1737 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1738 | if (DBG) log("dial: " + number); |
| 1739 | // No permission check needed here: This is just a wrapper around the |
| 1740 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1741 | // the UI before it does anything. |
| 1742 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1743 | final long identity = Binder.clearCallingIdentity(); |
| 1744 | try { |
| 1745 | String url = createTelUrl(number); |
| 1746 | if (url == null) { |
| 1747 | return; |
| 1748 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1750 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1751 | PhoneConstants.State state = mCM.getState(subId); |
| 1752 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1753 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1754 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1755 | mApp.startActivity(intent); |
| 1756 | } |
| 1757 | } finally { |
| 1758 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1763 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1764 | } |
| 1765 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1766 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1767 | if (DBG) log("call: " + number); |
| 1768 | |
| 1769 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1770 | // need to do a permission check since we're calling startActivity() |
| 1771 | // from the context of the phone app. |
| 1772 | enforceCallPermission(); |
| 1773 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1774 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1775 | != AppOpsManager.MODE_ALLOWED) { |
| 1776 | return; |
| 1777 | } |
| 1778 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1779 | final long identity = Binder.clearCallingIdentity(); |
| 1780 | try { |
| 1781 | String url = createTelUrl(number); |
| 1782 | if (url == null) { |
| 1783 | return; |
| 1784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1786 | boolean isValid = false; |
| 1787 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1788 | if (slist != null) { |
| 1789 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1790 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1791 | isValid = true; |
| 1792 | break; |
| 1793 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1794 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1795 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1796 | if (!isValid) { |
| 1797 | return; |
| 1798 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1799 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1800 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1801 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1802 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1803 | mApp.startActivity(intent); |
| 1804 | } finally { |
| 1805 | Binder.restoreCallingIdentity(identity); |
| 1806 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1809 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1810 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1811 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1812 | } |
| 1813 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1814 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1815 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1816 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1817 | } |
| 1818 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1819 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1820 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1821 | |
| 1822 | final long identity = Binder.clearCallingIdentity(); |
| 1823 | try { |
| 1824 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1825 | checkSimPin.start(); |
| 1826 | return checkSimPin.unlockSim(null, pin); |
| 1827 | } finally { |
| 1828 | Binder.restoreCallingIdentity(identity); |
| 1829 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1832 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1833 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1834 | |
| 1835 | final long identity = Binder.clearCallingIdentity(); |
| 1836 | try { |
| 1837 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1838 | checkSimPuk.start(); |
| 1839 | return checkSimPuk.unlockSim(puk, pin); |
| 1840 | } finally { |
| 1841 | Binder.restoreCallingIdentity(identity); |
| 1842 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1846 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1847 | * a synchronous one. |
| 1848 | */ |
| 1849 | private static class UnlockSim extends Thread { |
| 1850 | |
| 1851 | private final IccCard mSimCard; |
| 1852 | |
| 1853 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1854 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1855 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1856 | |
| 1857 | // For replies from SimCard interface |
| 1858 | private Handler mHandler; |
| 1859 | |
| 1860 | // For async handler to identify request type |
| 1861 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1862 | |
| 1863 | public UnlockSim(IccCard simCard) { |
| 1864 | mSimCard = simCard; |
| 1865 | } |
| 1866 | |
| 1867 | @Override |
| 1868 | public void run() { |
| 1869 | Looper.prepare(); |
| 1870 | synchronized (UnlockSim.this) { |
| 1871 | mHandler = new Handler() { |
| 1872 | @Override |
| 1873 | public void handleMessage(Message msg) { |
| 1874 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1875 | switch (msg.what) { |
| 1876 | case SUPPLY_PIN_COMPLETE: |
| 1877 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1878 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1879 | mRetryCount = msg.arg1; |
| 1880 | if (ar.exception != null) { |
| 1881 | if (ar.exception instanceof CommandException && |
| 1882 | ((CommandException)(ar.exception)).getCommandError() |
| 1883 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1884 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1885 | } else { |
| 1886 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1887 | } |
| 1888 | } else { |
| 1889 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1890 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1891 | mDone = true; |
| 1892 | UnlockSim.this.notifyAll(); |
| 1893 | } |
| 1894 | break; |
| 1895 | } |
| 1896 | } |
| 1897 | }; |
| 1898 | UnlockSim.this.notifyAll(); |
| 1899 | } |
| 1900 | Looper.loop(); |
| 1901 | } |
| 1902 | |
| 1903 | /* |
| 1904 | * Use PIN or PUK to unlock SIM card |
| 1905 | * |
| 1906 | * If PUK is null, unlock SIM card with PIN |
| 1907 | * |
| 1908 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1909 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1910 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1911 | |
| 1912 | while (mHandler == null) { |
| 1913 | try { |
| 1914 | wait(); |
| 1915 | } catch (InterruptedException e) { |
| 1916 | Thread.currentThread().interrupt(); |
| 1917 | } |
| 1918 | } |
| 1919 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1920 | |
| 1921 | if (puk == null) { |
| 1922 | mSimCard.supplyPin(pin, callback); |
| 1923 | } else { |
| 1924 | mSimCard.supplyPuk(puk, pin, callback); |
| 1925 | } |
| 1926 | |
| 1927 | while (!mDone) { |
| 1928 | try { |
| 1929 | Log.d(LOG_TAG, "wait for done"); |
| 1930 | wait(); |
| 1931 | } catch (InterruptedException e) { |
| 1932 | // Restore the interrupted status |
| 1933 | Thread.currentThread().interrupt(); |
| 1934 | } |
| 1935 | } |
| 1936 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1937 | int[] resultArray = new int[2]; |
| 1938 | resultArray[0] = mResult; |
| 1939 | resultArray[1] = mRetryCount; |
| 1940 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1945 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1946 | |
| 1947 | } |
| 1948 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1949 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1950 | // No permission check needed here: this call is harmless, and it's |
| 1951 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1952 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1953 | final long identity = Binder.clearCallingIdentity(); |
| 1954 | try { |
| 1955 | final Phone phone = getPhone(subId); |
| 1956 | if (phone != null) { |
| 1957 | phone.updateServiceLocation(); |
| 1958 | } |
| 1959 | } finally { |
| 1960 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1961 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1964 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1965 | @Override |
| 1966 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1967 | return isRadioOnWithFeature(callingPackage, null); |
| 1968 | } |
| 1969 | |
| 1970 | |
| 1971 | @Override |
| 1972 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1973 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1974 | callingFeatureId); |
| 1975 | } |
| 1976 | |
| 1977 | @Deprecated |
| 1978 | @Override |
| 1979 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1980 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1983 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1984 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1985 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1986 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1987 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1988 | return false; |
| 1989 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1990 | |
| 1991 | final long identity = Binder.clearCallingIdentity(); |
| 1992 | try { |
| 1993 | return isRadioOnForSubscriber(subId); |
| 1994 | } finally { |
| 1995 | Binder.restoreCallingIdentity(identity); |
| 1996 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2000 | final long identity = Binder.clearCallingIdentity(); |
| 2001 | try { |
| 2002 | final Phone phone = getPhone(subId); |
| 2003 | if (phone != null) { |
| 2004 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2005 | } else { |
| 2006 | return false; |
| 2007 | } |
| 2008 | } finally { |
| 2009 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2010 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2014 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2015 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2016 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2017 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2018 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2019 | |
| 2020 | final long identity = Binder.clearCallingIdentity(); |
| 2021 | try { |
| 2022 | final Phone phone = getPhone(subId); |
| 2023 | if (phone != null) { |
| 2024 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2025 | } |
| 2026 | } finally { |
| 2027 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2028 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2032 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2035 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2036 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2037 | |
| 2038 | final long identity = Binder.clearCallingIdentity(); |
| 2039 | try { |
| 2040 | final Phone phone = getPhone(subId); |
| 2041 | if (phone == null) { |
| 2042 | return false; |
| 2043 | } |
| 2044 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2045 | toggleRadioOnOffForSubscriber(subId); |
| 2046 | } |
| 2047 | return true; |
| 2048 | } finally { |
| 2049 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2050 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2051 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2052 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2053 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2054 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2055 | /* |
| 2056 | * If any of the Radios are available, it will need to be |
| 2057 | * shutdown. So return true if any Radio is available. |
| 2058 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2059 | final long identity = Binder.clearCallingIdentity(); |
| 2060 | try { |
| 2061 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2062 | Phone phone = PhoneFactory.getPhone(i); |
| 2063 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2064 | } |
| 2065 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2066 | return false; |
| 2067 | } finally { |
| 2068 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2069 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2072 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2073 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2074 | enforceModifyPermission(); |
| 2075 | |
| 2076 | final long identity = Binder.clearCallingIdentity(); |
| 2077 | try { |
| 2078 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2079 | logv("Shutting down Phone " + i); |
| 2080 | shutdownRadioUsingPhoneId(i); |
| 2081 | } |
| 2082 | } finally { |
| 2083 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2088 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2089 | if (phone != null && phone.isRadioAvailable()) { |
| 2090 | phone.shutdownRadio(); |
| 2091 | } |
| 2092 | } |
| 2093 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2094 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2095 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2096 | |
| 2097 | final long identity = Binder.clearCallingIdentity(); |
| 2098 | try { |
| 2099 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2100 | if (defaultPhone != null) { |
| 2101 | defaultPhone.setRadioPower(turnOn); |
| 2102 | return true; |
| 2103 | } else { |
| 2104 | loge("There's no default phone."); |
| 2105 | return false; |
| 2106 | } |
| 2107 | } finally { |
| 2108 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2109 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2112 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2113 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2114 | |
| 2115 | final long identity = Binder.clearCallingIdentity(); |
| 2116 | try { |
| 2117 | final Phone phone = getPhone(subId); |
| 2118 | if (phone != null) { |
| 2119 | phone.setRadioPower(turnOn); |
| 2120 | return true; |
| 2121 | } else { |
| 2122 | return false; |
| 2123 | } |
| 2124 | } finally { |
| 2125 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2126 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2129 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2130 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2131 | public boolean enableDataConnectivity() { |
| 2132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2133 | |
| 2134 | final long identity = Binder.clearCallingIdentity(); |
| 2135 | try { |
| 2136 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2137 | final Phone phone = getPhone(subId); |
| 2138 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2139 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2140 | return true; |
| 2141 | } else { |
| 2142 | return false; |
| 2143 | } |
| 2144 | } finally { |
| 2145 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2146 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2149 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2150 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2151 | public boolean disableDataConnectivity() { |
| 2152 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2153 | |
| 2154 | final long identity = Binder.clearCallingIdentity(); |
| 2155 | try { |
| 2156 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2157 | final Phone phone = getPhone(subId); |
| 2158 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2159 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2160 | return true; |
| 2161 | } else { |
| 2162 | return false; |
| 2163 | } |
| 2164 | } finally { |
| 2165 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2166 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2169 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2170 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2171 | final long identity = Binder.clearCallingIdentity(); |
| 2172 | try { |
| 2173 | final Phone phone = getPhone(subId); |
| 2174 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2175 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2176 | } else { |
| 2177 | return false; |
| 2178 | } |
| 2179 | } finally { |
| 2180 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2181 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2185 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2188 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2189 | enforceCallPermission(); |
| 2190 | |
| 2191 | final long identity = Binder.clearCallingIdentity(); |
| 2192 | try { |
| 2193 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2194 | return; |
| 2195 | } |
| 2196 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2197 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2198 | } finally { |
| 2199 | Binder.restoreCallingIdentity(identity); |
| 2200 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2201 | }; |
| 2202 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2203 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2204 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2205 | |
| 2206 | final long identity = Binder.clearCallingIdentity(); |
| 2207 | try { |
| 2208 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2209 | return false; |
| 2210 | } |
| 2211 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2212 | } finally { |
| 2213 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2214 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2217 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2218 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2221 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2222 | final long identity = Binder.clearCallingIdentity(); |
| 2223 | try { |
| 2224 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2225 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2226 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2227 | } finally { |
| 2228 | Binder.restoreCallingIdentity(identity); |
| 2229 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2232 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2233 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2234 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2235 | } |
| 2236 | |
| 2237 | @Override |
| 2238 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2239 | final long identity = Binder.clearCallingIdentity(); |
| 2240 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2241 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2242 | if (phone != null) { |
| 2243 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2244 | } else { |
| 2245 | return PhoneConstantConversions.convertDataState( |
| 2246 | PhoneConstants.DataState.DISCONNECTED); |
| 2247 | } |
| 2248 | } finally { |
| 2249 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2250 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2253 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2254 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2255 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2256 | } |
| 2257 | |
| 2258 | @Override |
| 2259 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2260 | final long identity = Binder.clearCallingIdentity(); |
| 2261 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2262 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2263 | if (phone != null) { |
| 2264 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2265 | } else { |
| 2266 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2267 | } |
| 2268 | } finally { |
| 2269 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2270 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2274 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2275 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2276 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2277 | |
| 2278 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2279 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2280 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2281 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2282 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2283 | .setCallingPid(Binder.getCallingPid()) |
| 2284 | .setCallingUid(Binder.getCallingUid()) |
| 2285 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2286 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2287 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2288 | .build()); |
| 2289 | switch (locationResult) { |
| 2290 | case DENIED_HARD: |
| 2291 | throw new SecurityException("Not allowed to access cell location"); |
| 2292 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2293 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2294 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2297 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2298 | final long identity = Binder.clearCallingIdentity(); |
| 2299 | try { |
| 2300 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2301 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2302 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2303 | } finally { |
| 2304 | Binder.restoreCallingIdentity(identity); |
| 2305 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2308 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2309 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2310 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2311 | // registered cell info, so return a NULL country instead. |
| 2312 | final long identity = Binder.clearCallingIdentity(); |
| 2313 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2314 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2315 | // Get default phone in this case. |
| 2316 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2317 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2318 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2319 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2320 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2321 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2322 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2323 | mApp.getFeatureId())) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2324 | return ""; |
| 2325 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2326 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2327 | if (phone != null) { |
| 2328 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2329 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2330 | if (sst != null) { |
| 2331 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2332 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2333 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2334 | return lt.getCurrentCountry(); |
| 2335 | } else if (emergencyNumberTracker != null) { |
| 2336 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2337 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2342 | } finally { |
| 2343 | Binder.restoreCallingIdentity(identity); |
| 2344 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2348 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2349 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2352 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2353 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | mApp.enforceCallingOrSelfPermission( |
| 2355 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2356 | |
| 2357 | final long identity = Binder.clearCallingIdentity(); |
| 2358 | try { |
| 2359 | final Phone phone = getPhone(subId); |
| 2360 | if (phone != null) { |
| 2361 | phone.enableLocationUpdates(); |
| 2362 | } |
| 2363 | } finally { |
| 2364 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2365 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | @Override |
| 2369 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2370 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2373 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2374 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | mApp.enforceCallingOrSelfPermission( |
| 2376 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2377 | |
| 2378 | final long identity = Binder.clearCallingIdentity(); |
| 2379 | try { |
| 2380 | final Phone phone = getPhone(subId); |
| 2381 | if (phone != null) { |
| 2382 | phone.disableLocationUpdates(); |
| 2383 | } |
| 2384 | } finally { |
| 2385 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2386 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2389 | /** |
| 2390 | * Returns the target SDK version number for a given package name. |
| 2391 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2392 | * This call MUST be invoked before clearing the calling UID. |
| 2393 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2394 | * @return target SDK if the package is found or INT_MAX. |
| 2395 | */ |
| 2396 | private int getTargetSdk(String packageName) { |
| 2397 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2398 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2399 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2400 | if (ai != null) return ai.targetSdkVersion; |
| 2401 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2402 | loge("Failed to get package info for pkg=" |
| 2403 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2404 | } |
| 2405 | return Integer.MAX_VALUE; |
| 2406 | } |
| 2407 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | @Override |
| 2409 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2410 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2411 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2412 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2413 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2414 | throw new SecurityException( |
| 2415 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2416 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2417 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2418 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2419 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2420 | return null; |
| 2421 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2422 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2423 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2424 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2425 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2426 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2427 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2428 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2429 | for (CellInfo ci : info) { |
| 2430 | if (ci instanceof CellInfoGsm) { |
| 2431 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2432 | } else if (ci instanceof CellInfoWcdma) { |
| 2433 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2434 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2436 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2439 | private List<CellInfo> getCachedCellInfo() { |
| 2440 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2441 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2442 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2443 | if (info != null) cellInfos.addAll(info); |
| 2444 | } |
| 2445 | return cellInfos; |
| 2446 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2447 | |
| 2448 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2449 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2450 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2451 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2452 | |
| 2453 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2454 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2455 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2456 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2457 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2458 | .setCallingPid(Binder.getCallingPid()) |
| 2459 | .setCallingUid(Binder.getCallingUid()) |
| 2460 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2461 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2462 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2463 | .build()); |
| 2464 | switch (locationResult) { |
| 2465 | case DENIED_HARD: |
| 2466 | throw new SecurityException("Not allowed to access cell info"); |
| 2467 | case DENIED_SOFT: |
| 2468 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2471 | final int targetSdk = getTargetSdk(callingPackage); |
| 2472 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2473 | return getCachedCellInfo(); |
| 2474 | } |
| 2475 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2476 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2477 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | final long identity = Binder.clearCallingIdentity(); |
| 2479 | try { |
| 2480 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2481 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2482 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2483 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2484 | if (info != null) cellInfos.addAll(info); |
| 2485 | } |
| 2486 | return cellInfos; |
| 2487 | } finally { |
| 2488 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | } |
| 2490 | } |
| 2491 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2492 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2493 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2494 | String callingFeatureId) { |
| 2495 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2496 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2500 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2501 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2502 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2503 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2506 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2507 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2508 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2509 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2510 | |
| 2511 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2512 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2513 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2514 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2515 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2516 | .setCallingPid(Binder.getCallingPid()) |
| 2517 | .setCallingUid(Binder.getCallingUid()) |
| 2518 | .setMethod("requestCellInfoUpdate") |
| 2519 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2520 | .build()); |
| 2521 | switch (locationResult) { |
| 2522 | case DENIED_HARD: |
| 2523 | throw new SecurityException("Not allowed to access cell info"); |
| 2524 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2525 | try { |
| 2526 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2527 | } catch (RemoteException re) { |
| 2528 | // Drop without consequences |
| 2529 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2530 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2533 | |
| 2534 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2535 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2536 | |
| 2537 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2538 | } |
| 2539 | |
| 2540 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2542 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2543 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | |
| 2545 | final long identity = Binder.clearCallingIdentity(); |
| 2546 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2547 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | } finally { |
| 2549 | Binder.restoreCallingIdentity(identity); |
| 2550 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2553 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2554 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2555 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2556 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2557 | return null; |
| 2558 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2559 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2560 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2561 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2562 | return null; |
| 2563 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | |
| 2565 | final long identity = Binder.clearCallingIdentity(); |
| 2566 | try { |
| 2567 | return phone.getImei(); |
| 2568 | } finally { |
| 2569 | Binder.restoreCallingIdentity(identity); |
| 2570 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2574 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2575 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2576 | String tac = null; |
| 2577 | if (phone != null) { |
| 2578 | String imei = phone.getImei(); |
| 2579 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2580 | } |
| 2581 | return tac; |
| 2582 | } |
| 2583 | |
| 2584 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2585 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2586 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2587 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2588 | return null; |
| 2589 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2590 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2591 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2592 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2593 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2594 | return null; |
| 2595 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2596 | |
| 2597 | final long identity = Binder.clearCallingIdentity(); |
| 2598 | try { |
| 2599 | return phone.getMeid(); |
| 2600 | } finally { |
| 2601 | Binder.restoreCallingIdentity(identity); |
| 2602 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2606 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2607 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2608 | String manufacturerCode = null; |
| 2609 | if (phone != null) { |
| 2610 | String meid = phone.getMeid(); |
| 2611 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2612 | } |
| 2613 | return manufacturerCode; |
| 2614 | } |
| 2615 | |
| 2616 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2617 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2618 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2619 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2620 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2621 | return null; |
| 2622 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2623 | int subId = phone.getSubId(); |
| 2624 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2625 | mApp, subId, callingPackage, callingFeatureId, |
| 2626 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2627 | return null; |
| 2628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 | |
| 2630 | final long identity = Binder.clearCallingIdentity(); |
| 2631 | try { |
| 2632 | return phone.getDeviceSvn(); |
| 2633 | } finally { |
| 2634 | Binder.restoreCallingIdentity(identity); |
| 2635 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2636 | } |
| 2637 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2638 | @Override |
| 2639 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | final long identity = Binder.clearCallingIdentity(); |
| 2641 | try { |
| 2642 | final Phone phone = getPhone(subId); |
| 2643 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2644 | } finally { |
| 2645 | Binder.restoreCallingIdentity(identity); |
| 2646 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | @Override |
| 2650 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | final long identity = Binder.clearCallingIdentity(); |
| 2652 | try { |
| 2653 | final Phone phone = getPhone(subId); |
| 2654 | return phone == null ? null : phone.getCarrierName(); |
| 2655 | } finally { |
| 2656 | Binder.restoreCallingIdentity(identity); |
| 2657 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2658 | } |
| 2659 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2660 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2661 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2662 | final long identity = Binder.clearCallingIdentity(); |
| 2663 | try { |
| 2664 | final Phone phone = getPhone(subId); |
| 2665 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2666 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2667 | } finally { |
| 2668 | Binder.restoreCallingIdentity(identity); |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2673 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2674 | final long identity = Binder.clearCallingIdentity(); |
| 2675 | try { |
| 2676 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2677 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2678 | } finally { |
| 2679 | Binder.restoreCallingIdentity(identity); |
| 2680 | } |
| 2681 | } |
| 2682 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2683 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2684 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2685 | if (!isSubscriptionMccMnc) { |
| 2686 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2687 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2688 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2689 | if (phone == null) { |
| 2690 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2691 | } |
| 2692 | final long identity = Binder.clearCallingIdentity(); |
| 2693 | try { |
| 2694 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2695 | } finally { |
| 2696 | Binder.restoreCallingIdentity(identity); |
| 2697 | } |
| 2698 | } |
| 2699 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2700 | // |
| 2701 | // Internal helper methods. |
| 2702 | // |
| 2703 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2704 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2705 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2706 | * |
| 2707 | * @throws SecurityException if the caller does not have the required permission |
| 2708 | */ |
| 2709 | private void enforceModifyPermission() { |
| 2710 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2711 | } |
| 2712 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2713 | /** |
| 2714 | * Make sure the caller is system. |
| 2715 | * |
| 2716 | * @throws SecurityException if the caller is not system. |
| 2717 | */ |
| 2718 | private void enforceSystemCaller() { |
| 2719 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2720 | throw new SecurityException("Caller must be system"); |
| 2721 | } |
| 2722 | } |
| 2723 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2724 | private void enforceActiveEmergencySessionPermission() { |
| 2725 | mApp.enforceCallingOrSelfPermission( |
| 2726 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2727 | } |
| 2728 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | /** |
| 2730 | * Make sure the caller has the CALL_PHONE permission. |
| 2731 | * |
| 2732 | * @throws SecurityException if the caller does not have the required permission |
| 2733 | */ |
| 2734 | private void enforceCallPermission() { |
| 2735 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2736 | } |
| 2737 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2738 | private void enforceSettingsPermission() { |
| 2739 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | private String createTelUrl(String number) { |
| 2743 | if (TextUtils.isEmpty(number)) { |
| 2744 | return null; |
| 2745 | } |
| 2746 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2747 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2748 | } |
| 2749 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2750 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2751 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2752 | } |
| 2753 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2754 | private static void logv(String msg) { |
| 2755 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2756 | } |
| 2757 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2758 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2760 | } |
| 2761 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2762 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2763 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2764 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2767 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2768 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | final long identity = Binder.clearCallingIdentity(); |
| 2770 | try { |
| 2771 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2772 | if (phone == null) { |
| 2773 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2774 | } else { |
| 2775 | return phone.getPhoneType(); |
| 2776 | } |
| 2777 | } finally { |
| 2778 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | /** |
| 2783 | * Returns the CDMA ERI icon index to display |
| 2784 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2785 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2786 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2787 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2788 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2791 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2792 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2793 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2794 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2795 | mApp, subId, callingPackage, callingFeatureId, |
| 2796 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2797 | return -1; |
| 2798 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2799 | |
| 2800 | final long identity = Binder.clearCallingIdentity(); |
| 2801 | try { |
| 2802 | final Phone phone = getPhone(subId); |
| 2803 | if (phone != null) { |
| 2804 | return phone.getCdmaEriIconIndex(); |
| 2805 | } else { |
| 2806 | return -1; |
| 2807 | } |
| 2808 | } finally { |
| 2809 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | /** |
| 2814 | * Returns the CDMA ERI icon mode, |
| 2815 | * 0 - ON |
| 2816 | * 1 - FLASHING |
| 2817 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2818 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2819 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2820 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2821 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2824 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2825 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2826 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2827 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2828 | mApp, subId, callingPackage, callingFeatureId, |
| 2829 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2830 | return -1; |
| 2831 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2832 | |
| 2833 | final long identity = Binder.clearCallingIdentity(); |
| 2834 | try { |
| 2835 | final Phone phone = getPhone(subId); |
| 2836 | if (phone != null) { |
| 2837 | return phone.getCdmaEriIconMode(); |
| 2838 | } else { |
| 2839 | return -1; |
| 2840 | } |
| 2841 | } finally { |
| 2842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2843 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | /** |
| 2847 | * Returns the CDMA ERI text, |
| 2848 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2849 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2850 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2851 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2852 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2855 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2856 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2857 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2858 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2859 | mApp, subId, callingPackage, callingFeatureId, |
| 2860 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2861 | return null; |
| 2862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2863 | |
| 2864 | final long identity = Binder.clearCallingIdentity(); |
| 2865 | try { |
| 2866 | final Phone phone = getPhone(subId); |
| 2867 | if (phone != null) { |
| 2868 | return phone.getCdmaEriText(); |
| 2869 | } else { |
| 2870 | return null; |
| 2871 | } |
| 2872 | } finally { |
| 2873 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2878 | * Returns the CDMA MDN. |
| 2879 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2880 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2881 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2882 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2883 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2884 | |
| 2885 | final long identity = Binder.clearCallingIdentity(); |
| 2886 | try { |
| 2887 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2888 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2889 | return phone.getLine1Number(); |
| 2890 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2891 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2892 | return null; |
| 2893 | } |
| 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | /** |
| 2900 | * Returns the CDMA MIN. |
| 2901 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2902 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2903 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2904 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2905 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2906 | |
| 2907 | final long identity = Binder.clearCallingIdentity(); |
| 2908 | try { |
| 2909 | final Phone phone = getPhone(subId); |
| 2910 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2911 | return phone.getCdmaMin(); |
| 2912 | } else { |
| 2913 | return null; |
| 2914 | } |
| 2915 | } finally { |
| 2916 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2920 | @Override |
| 2921 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2922 | INumberVerificationCallback callback, String callingPackage) { |
| 2923 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2924 | != PERMISSION_GRANTED) { |
| 2925 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2926 | } |
| 2927 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2928 | |
| 2929 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2930 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2931 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2932 | } |
| 2933 | |
| 2934 | if (range == null) { |
| 2935 | throw new NullPointerException("Range must be non-null"); |
| 2936 | } |
| 2937 | |
| 2938 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2939 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2940 | |
| 2941 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2942 | } |
| 2943 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2944 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2945 | * Returns true if CDMA provisioning needs to run. |
| 2946 | */ |
| 2947 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2948 | final long identity = Binder.clearCallingIdentity(); |
| 2949 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2950 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
| 2953 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2957 | * Sets the voice mail number of a given subId. |
| 2958 | */ |
| 2959 | @Override |
| 2960 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2961 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2962 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2963 | |
| 2964 | final long identity = Binder.clearCallingIdentity(); |
| 2965 | try { |
| 2966 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2967 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2968 | return success; |
| 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
| 2971 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2972 | } |
| 2973 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2974 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2975 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2976 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2977 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2978 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2979 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2980 | throw new SecurityException("caller must be system dialer"); |
| 2981 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2982 | |
| 2983 | final long identity = Binder.clearCallingIdentity(); |
| 2984 | try { |
| 2985 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2986 | if (phoneAccountHandle == null) { |
| 2987 | return null; |
| 2988 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2989 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2992 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2996 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2997 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2998 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2999 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3000 | mApp, subId, callingPackage, callingFeatureId, |
| 3001 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3002 | return null; |
| 3003 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3004 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3005 | final long identity = Binder.clearCallingIdentity(); |
| 3006 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3007 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
| 3010 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3014 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3015 | VisualVoicemailSmsFilterSettings settings) { |
| 3016 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | |
| 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3021 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | } finally { |
| 3023 | Binder.restoreCallingIdentity(identity); |
| 3024 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3028 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3029 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | |
| 3031 | final long identity = Binder.clearCallingIdentity(); |
| 3032 | try { |
| 3033 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3034 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3035 | } finally { |
| 3036 | Binder.restoreCallingIdentity(identity); |
| 3037 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3041 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3042 | String callingPackage, int subId) { |
| 3043 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3044 | |
| 3045 | final long identity = Binder.clearCallingIdentity(); |
| 3046 | try { |
| 3047 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3048 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3049 | } finally { |
| 3050 | Binder.restoreCallingIdentity(identity); |
| 3051 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3055 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3056 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3057 | |
| 3058 | final long identity = Binder.clearCallingIdentity(); |
| 3059 | try { |
| 3060 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3061 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(identity); |
| 3064 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | @Override |
| 3068 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 3069 | String number, int port, String text, PendingIntent sentIntent) { |
| 3070 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3071 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3072 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3073 | SmsController smsController = PhoneFactory.getSmsController(); |
| 3074 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 3075 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3076 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3077 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3078 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3079 | * Sets the voice activation state of a given subId. |
| 3080 | */ |
| 3081 | @Override |
| 3082 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3083 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3084 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3085 | |
| 3086 | final long identity = Binder.clearCallingIdentity(); |
| 3087 | try { |
| 3088 | final Phone phone = getPhone(subId); |
| 3089 | if (phone != null) { |
| 3090 | phone.setVoiceActivationState(activationState); |
| 3091 | } else { |
| 3092 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3093 | } |
| 3094 | } finally { |
| 3095 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | /** |
| 3100 | * Sets the data activation state of a given subId. |
| 3101 | */ |
| 3102 | @Override |
| 3103 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3105 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3106 | |
| 3107 | final long identity = Binder.clearCallingIdentity(); |
| 3108 | try { |
| 3109 | final Phone phone = getPhone(subId); |
| 3110 | if (phone != null) { |
| 3111 | phone.setDataActivationState(activationState); |
| 3112 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3113 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3114 | } |
| 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | /** |
| 3121 | * Returns the voice activation state of a given subId. |
| 3122 | */ |
| 3123 | @Override |
| 3124 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3125 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3126 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3127 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3128 | final long identity = Binder.clearCallingIdentity(); |
| 3129 | try { |
| 3130 | if (phone != null) { |
| 3131 | return phone.getVoiceActivationState(); |
| 3132 | } else { |
| 3133 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3134 | } |
| 3135 | } finally { |
| 3136 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | /** |
| 3141 | * Returns the data activation state of a given subId. |
| 3142 | */ |
| 3143 | @Override |
| 3144 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3145 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3146 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3147 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3148 | final long identity = Binder.clearCallingIdentity(); |
| 3149 | try { |
| 3150 | if (phone != null) { |
| 3151 | return phone.getDataActivationState(); |
| 3152 | } else { |
| 3153 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3154 | } |
| 3155 | } finally { |
| 3156 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3161 | * Returns the unread count of voicemails for a subId |
| 3162 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3163 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3164 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3165 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3166 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3167 | mApp, subId, callingPackage, callingFeatureId, |
| 3168 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3169 | return 0; |
| 3170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3171 | final long identity = Binder.clearCallingIdentity(); |
| 3172 | try { |
| 3173 | final Phone phone = getPhone(subId); |
| 3174 | if (phone != null) { |
| 3175 | return phone.getVoiceMessageCount(); |
| 3176 | } else { |
| 3177 | return 0; |
| 3178 | } |
| 3179 | } finally { |
| 3180 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3181 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3185 | * returns true, if the device is in a state where both voice and data |
| 3186 | * are supported simultaneously. This can change based on location or network condition. |
| 3187 | */ |
| 3188 | @Override |
| 3189 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
| 3192 | final Phone phone = getPhone(subId); |
| 3193 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3194 | } finally { |
| 3195 | Binder.restoreCallingIdentity(identity); |
| 3196 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3200 | * Send the dialer code if called from the current default dialer or the caller has |
| 3201 | * carrier privilege. |
| 3202 | * @param inputCode The dialer code to send |
| 3203 | */ |
| 3204 | @Override |
| 3205 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3206 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3207 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3208 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3209 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3210 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3211 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3212 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3213 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3214 | |
| 3215 | final long identity = Binder.clearCallingIdentity(); |
| 3216 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3217 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3218 | } finally { |
| 3219 | Binder.restoreCallingIdentity(identity); |
| 3220 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3221 | } |
| 3222 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3223 | @Override |
| 3224 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3225 | TelephonyPermissions |
| 3226 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3227 | mApp, subId, "getNetworkSelectionMode"); |
| 3228 | final long identity = Binder.clearCallingIdentity(); |
| 3229 | try { |
| 3230 | if (!isActiveSubscription(subId)) { |
| 3231 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3232 | } |
| 3233 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3236 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3239 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3240 | public boolean isInEmergencySmsMode() { |
| 3241 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3242 | final long identity = Binder.clearCallingIdentity(); |
| 3243 | try { |
| 3244 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3245 | if (phone.isInEmergencySmsMode()) { |
| 3246 | return true; |
| 3247 | } |
| 3248 | } |
| 3249 | } finally { |
| 3250 | Binder.restoreCallingIdentity(identity); |
| 3251 | } |
| 3252 | return false; |
| 3253 | } |
| 3254 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3255 | /** |
| 3256 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3257 | * @param subId The subscription to use to check the configuration. |
| 3258 | * @param c The callback that will be used to send the result. |
| 3259 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3260 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3261 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3262 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3263 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3264 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3265 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3266 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3267 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3268 | "IMS not available on device."); |
| 3269 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3270 | final long token = Binder.clearCallingIdentity(); |
| 3271 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3272 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3273 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3274 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3275 | } catch (ImsException e) { |
| 3276 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(token); |
| 3279 | } |
| 3280 | } |
| 3281 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3282 | /** |
| 3283 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3284 | * @param subId The subscription to use to check the configuration. |
| 3285 | * @param c The callback that will be used to send the result. |
| 3286 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3287 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3288 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3289 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3290 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3291 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3292 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3293 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3294 | final long token = Binder.clearCallingIdentity(); |
| 3295 | try { |
| 3296 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3297 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3298 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3299 | } catch (ImsException e) { |
| 3300 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3301 | + "is inactive, ignoring unregister."); |
| 3302 | // If the subscription is no longer active, just return, since the callback |
| 3303 | // will already have been removed internally. |
| 3304 | } finally { |
| 3305 | Binder.restoreCallingIdentity(token); |
| 3306 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3309 | /** |
| 3310 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3311 | */ |
| 3312 | @Override |
| 3313 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3314 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3315 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3316 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3317 | "IMS not available on device."); |
| 3318 | } |
| 3319 | final long token = Binder.clearCallingIdentity(); |
| 3320 | try { |
| 3321 | Phone phone = getPhone(subId); |
| 3322 | if (phone == null) { |
| 3323 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3324 | + subId + "'"); |
| 3325 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3326 | } |
| 3327 | phone.getImsRegistrationState(regState -> { |
| 3328 | try { |
| 3329 | consumer.accept((regState == null) |
| 3330 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3331 | } catch (RemoteException e) { |
| 3332 | // Ignore if the remote process is no longer available to call back. |
| 3333 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3334 | } |
| 3335 | }); |
| 3336 | } finally { |
| 3337 | Binder.restoreCallingIdentity(token); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | /** |
| 3342 | * Get the transport type for the IMS service registration state. |
| 3343 | */ |
| 3344 | @Override |
| 3345 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3346 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3347 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3348 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3349 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3350 | "IMS not available on device."); |
| 3351 | } |
| 3352 | final long token = Binder.clearCallingIdentity(); |
| 3353 | try { |
| 3354 | Phone phone = getPhone(subId); |
| 3355 | if (phone == null) { |
| 3356 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3357 | + subId + "'"); |
| 3358 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3359 | } |
| 3360 | phone.getImsRegistrationTech(regTech -> { |
| 3361 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3362 | int regTechConverted = (regTech == null) |
| 3363 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3364 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3365 | regTechConverted); |
| 3366 | try { |
| 3367 | consumer.accept(regTechConverted); |
| 3368 | } catch (RemoteException e) { |
| 3369 | // Ignore if the remote process is no longer available to call back. |
| 3370 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3371 | } |
| 3372 | }); |
| 3373 | } finally { |
| 3374 | Binder.restoreCallingIdentity(token); |
| 3375 | } |
| 3376 | } |
| 3377 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3378 | /** |
| 3379 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3380 | * @param subId The subscription to use to check the configuration. |
| 3381 | * @param c The callback that will be used to send the result. |
| 3382 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3383 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3384 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3385 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3386 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3387 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3388 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3389 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3390 | "IMS not available on device."); |
| 3391 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3392 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3393 | final long token = Binder.clearCallingIdentity(); |
| 3394 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3395 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3396 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3397 | } catch (ImsException e) { |
| 3398 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3399 | } finally { |
| 3400 | Binder.restoreCallingIdentity(token); |
| 3401 | } |
| 3402 | } |
| 3403 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3404 | /** |
| 3405 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3406 | * @param subId The subscription to use to check the configuration. |
| 3407 | * @param c The callback that will be used to send the result. |
| 3408 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3409 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3410 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3411 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3412 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3413 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3414 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3415 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3416 | |
| 3417 | final long token = Binder.clearCallingIdentity(); |
| 3418 | try { |
| 3419 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3420 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3421 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3422 | } catch (ImsException e) { |
| 3423 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3424 | + "is inactive, ignoring unregister."); |
| 3425 | // If the subscription is no longer active, just return, since the callback |
| 3426 | // will already have been removed internally. |
| 3427 | } finally { |
| 3428 | Binder.restoreCallingIdentity(token); |
| 3429 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3433 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3434 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3435 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3436 | final long token = Binder.clearCallingIdentity(); |
| 3437 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3438 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3439 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3440 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3441 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3442 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3443 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3444 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3445 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3446 | } finally { |
| 3447 | Binder.restoreCallingIdentity(token); |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3452 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3453 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3454 | final long token = Binder.clearCallingIdentity(); |
| 3455 | try { |
| 3456 | Phone phone = getPhone(subId); |
| 3457 | if (phone == null) return false; |
| 3458 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3459 | } finally { |
| 3460 | Binder.restoreCallingIdentity(token); |
| 3461 | } |
| 3462 | } |
| 3463 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3464 | /** |
| 3465 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3466 | * subscription. |
| 3467 | * @param subId The subscription to use to check the configuration. |
| 3468 | * @param callback The callback that will be used to send the result. |
| 3469 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3470 | * @param transportType The transport type of the MmTelFeature capability. |
| 3471 | */ |
| 3472 | @Override |
| 3473 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3474 | int transportType) { |
| 3475 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3476 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3477 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3478 | "IMS not available on device."); |
| 3479 | } |
| 3480 | final long token = Binder.clearCallingIdentity(); |
| 3481 | try { |
| 3482 | int slotId = getSlotIndex(subId); |
| 3483 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3484 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3485 | + subId + "'"); |
| 3486 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3487 | } |
| 3488 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3489 | transportType, aBoolean -> { |
| 3490 | try { |
| 3491 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3492 | } catch (RemoteException e) { |
| 3493 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3494 | + "running. Ignore"); |
| 3495 | } |
| 3496 | }); |
| 3497 | } finally { |
| 3498 | Binder.restoreCallingIdentity(token); |
| 3499 | } |
| 3500 | } |
| 3501 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3502 | /** |
| 3503 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3504 | * @param subId The subscription to use to check the configuration. |
| 3505 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3506 | @Override |
| 3507 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3508 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3509 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3510 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3511 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3512 | final long token = Binder.clearCallingIdentity(); |
| 3513 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3514 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3515 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3516 | } catch (ImsException e) { |
| 3517 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3518 | } finally { |
| 3519 | Binder.restoreCallingIdentity(token); |
| 3520 | } |
| 3521 | } |
| 3522 | |
| 3523 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3524 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3525 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3526 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3527 | final long identity = Binder.clearCallingIdentity(); |
| 3528 | try { |
| 3529 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3530 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3531 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3532 | } catch (ImsException e) { |
| 3533 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3534 | } finally { |
| 3535 | Binder.restoreCallingIdentity(identity); |
| 3536 | } |
| 3537 | } |
| 3538 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3539 | /** |
| 3540 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3541 | * @param subId The subscription to use to check the configuration. |
| 3542 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3543 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3544 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3545 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3546 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3550 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3551 | } catch (ImsException e) { |
| 3552 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3553 | } finally { |
| 3554 | Binder.restoreCallingIdentity(identity); |
| 3555 | } |
| 3556 | } |
| 3557 | |
| 3558 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3559 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3561 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3562 | final long identity = Binder.clearCallingIdentity(); |
| 3563 | try { |
| 3564 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3565 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3566 | } catch (ImsException e) { |
| 3567 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3568 | } finally { |
| 3569 | Binder.restoreCallingIdentity(identity); |
| 3570 | } |
| 3571 | } |
| 3572 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3573 | /** |
| 3574 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3575 | * @param subId The subscription to use to check the configuration. |
| 3576 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3577 | @Override |
| 3578 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3579 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3580 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3581 | final long identity = Binder.clearCallingIdentity(); |
| 3582 | try { |
| 3583 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3584 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3586 | } catch (ImsException e) { |
| 3587 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3588 | } finally { |
| 3589 | Binder.restoreCallingIdentity(identity); |
| 3590 | } |
| 3591 | } |
| 3592 | |
| 3593 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3594 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3596 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3597 | final long identity = Binder.clearCallingIdentity(); |
| 3598 | try { |
| 3599 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3600 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3601 | } catch (ImsException e) { |
| 3602 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3603 | } finally { |
| 3604 | Binder.restoreCallingIdentity(identity); |
| 3605 | } |
| 3606 | } |
| 3607 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3608 | /** |
| 3609 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3610 | * @param subId The subscription to use to check the configuration. |
| 3611 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3612 | @Override |
| 3613 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3614 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3615 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3616 | final long identity = Binder.clearCallingIdentity(); |
| 3617 | try { |
| 3618 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3619 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3620 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3621 | } catch (ImsException e) { |
| 3622 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3623 | } finally { |
| 3624 | Binder.restoreCallingIdentity(identity); |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3629 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3631 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3632 | final long identity = Binder.clearCallingIdentity(); |
| 3633 | try { |
| 3634 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3635 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3636 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3637 | } catch (ImsException e) { |
| 3638 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3639 | } finally { |
| 3640 | Binder.restoreCallingIdentity(identity); |
| 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | @Override |
| 3645 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3647 | "setVoWiFiNonPersistent"); |
| 3648 | final long identity = Binder.clearCallingIdentity(); |
| 3649 | try { |
| 3650 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3651 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3652 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3653 | } catch (ImsException e) { |
| 3654 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
| 3657 | } |
| 3658 | } |
| 3659 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3660 | /** |
| 3661 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3662 | * @param subId The subscription to use to check the configuration. |
| 3663 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3664 | @Override |
| 3665 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3666 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3667 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3668 | final long identity = Binder.clearCallingIdentity(); |
| 3669 | try { |
| 3670 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3671 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3672 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3673 | } catch (ImsException e) { |
| 3674 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | @Override |
| 3681 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3683 | "setVoWiFiModeSetting"); |
| 3684 | final long identity = Binder.clearCallingIdentity(); |
| 3685 | try { |
| 3686 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3687 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3688 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3689 | } catch (ImsException e) { |
| 3690 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3691 | } finally { |
| 3692 | Binder.restoreCallingIdentity(identity); |
| 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | @Override |
| 3697 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3698 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3699 | final long identity = Binder.clearCallingIdentity(); |
| 3700 | try { |
| 3701 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3702 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3703 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3704 | } catch (ImsException e) { |
| 3705 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
| 3708 | } |
| 3709 | } |
| 3710 | |
| 3711 | @Override |
| 3712 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3713 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3714 | "setVoWiFiRoamingModeSetting"); |
| 3715 | final long identity = Binder.clearCallingIdentity(); |
| 3716 | try { |
| 3717 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3718 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3719 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3720 | } catch (ImsException e) { |
| 3721 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3722 | } finally { |
| 3723 | Binder.restoreCallingIdentity(identity); |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | @Override |
| 3728 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3729 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3730 | "setRttCapabilityEnabled"); |
| 3731 | final long identity = Binder.clearCallingIdentity(); |
| 3732 | try { |
| 3733 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3734 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3735 | } catch (ImsException e) { |
| 3736 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3737 | } finally { |
| 3738 | Binder.restoreCallingIdentity(identity); |
| 3739 | } |
| 3740 | } |
| 3741 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3742 | /** |
| 3743 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3744 | * @param subId The subscription to use to check the configuration. |
| 3745 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3746 | @Override |
| 3747 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3748 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3749 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3750 | final long identity = Binder.clearCallingIdentity(); |
| 3751 | try { |
| 3752 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3753 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3754 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3755 | } catch (ImsException e) { |
| 3756 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3757 | } finally { |
| 3758 | Binder.restoreCallingIdentity(identity); |
| 3759 | } |
| 3760 | } |
| 3761 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3762 | @Override |
| 3763 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3764 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3765 | final long identity = Binder.clearCallingIdentity(); |
| 3766 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3767 | if (!isImsAvailableOnDevice()) { |
| 3768 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3769 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3770 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3771 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3772 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3773 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3774 | } catch (ImsException e) { |
| 3775 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3776 | } finally { |
| 3777 | Binder.restoreCallingIdentity(identity); |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | @Override |
| 3782 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3783 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3784 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3785 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3786 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3787 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3788 | try { |
| 3789 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3790 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3791 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3792 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3793 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3794 | + "is inactive, ignoring unregister."); |
| 3795 | // If the subscription is no longer active, just return, since the callback will already |
| 3796 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3797 | } finally { |
| 3798 | Binder.restoreCallingIdentity(identity); |
| 3799 | } |
| 3800 | } |
| 3801 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3802 | |
| 3803 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3805 | message); |
| 3806 | } |
| 3807 | |
| 3808 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3809 | boolean isMmtelCapability) { |
| 3810 | Phone phone = getPhone(subId); |
| 3811 | if (phone == null) { |
| 3812 | loge("phone instance null for subid " + subId); |
| 3813 | return false; |
| 3814 | } |
| 3815 | if (isMmtelCapability) { |
| 3816 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3817 | return false; |
| 3818 | } |
| 3819 | } else { |
| 3820 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3821 | return false; |
| 3822 | } |
| 3823 | } |
| 3824 | return true; |
| 3825 | } |
| 3826 | |
| 3827 | @Override |
| 3828 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3829 | boolean isProvisioned) { |
| 3830 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3831 | |
| 3832 | final long identity = Binder.clearCallingIdentity(); |
| 3833 | try { |
| 3834 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3835 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3836 | return; |
| 3837 | } |
| 3838 | |
| 3839 | // this capability requires provisioning, route to the correct API. |
| 3840 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3841 | switch (capability) { |
| 3842 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3843 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3844 | ims.setEabProvisioned(isProvisioned); |
| 3845 | break; |
| 3846 | default: { |
| 3847 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3848 | + "rcs capability '" + capability + "', which does not require " |
| 3849 | + "provisioning."); |
| 3850 | } |
| 3851 | } |
| 3852 | } finally { |
| 3853 | Binder.restoreCallingIdentity(identity); |
| 3854 | } |
| 3855 | |
| 3856 | } |
| 3857 | |
| 3858 | |
| 3859 | @Override |
| 3860 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3861 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3862 | final long identity = Binder.clearCallingIdentity(); |
| 3863 | try { |
| 3864 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3865 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3866 | return true; |
| 3867 | } |
| 3868 | |
| 3869 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3870 | switch (capability) { |
| 3871 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3872 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3873 | return ims.isEabProvisionedOnDevice(); |
| 3874 | |
| 3875 | default: { |
| 3876 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3877 | + "capability '" + capability + "', which does not require " |
| 3878 | + "provisioning."); |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | } finally { |
| 3883 | Binder.restoreCallingIdentity(identity); |
| 3884 | } |
| 3885 | } |
| 3886 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3887 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3888 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3889 | boolean isProvisioned) { |
| 3890 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3891 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3892 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3893 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3894 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3895 | final long identity = Binder.clearCallingIdentity(); |
| 3896 | try { |
| 3897 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3898 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3899 | return; |
| 3900 | } |
| 3901 | |
| 3902 | // this capability requires provisioning, route to the correct API. |
| 3903 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3904 | switch (capability) { |
| 3905 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3906 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3907 | ims.setVolteProvisioned(isProvisioned); |
| 3908 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3909 | ims.setWfcProvisioned(isProvisioned); |
| 3910 | } |
| 3911 | break; |
| 3912 | } |
| 3913 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3914 | // There is currently no difference in VT provisioning type. |
| 3915 | ims.setVtProvisioned(isProvisioned); |
| 3916 | break; |
| 3917 | } |
| 3918 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3919 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3920 | // change the capability of the feature instead if needed. |
| 3921 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3922 | == isProvisioned) { |
| 3923 | // No change in provisioning. |
| 3924 | return; |
| 3925 | } |
| 3926 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3927 | try { |
| 3928 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3929 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3930 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3931 | + ", Exception" + e.getMessage()); |
| 3932 | } |
| 3933 | break; |
| 3934 | } |
| 3935 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3936 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3937 | + "MmTel capability '" + capability + "', which does not require " |
| 3938 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | } finally { |
| 3943 | Binder.restoreCallingIdentity(identity); |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | @Override |
| 3948 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3949 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3950 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3951 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3952 | } |
| 3953 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3954 | final long identity = Binder.clearCallingIdentity(); |
| 3955 | try { |
| 3956 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3957 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3958 | return true; |
| 3959 | } |
| 3960 | |
| 3961 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3962 | switch (capability) { |
| 3963 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3964 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3965 | return ims.isVolteProvisionedOnDevice(); |
| 3966 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3967 | return ims.isWfcProvisionedOnDevice(); |
| 3968 | } |
| 3969 | // This should never happen, since we are checking tech above to make sure it |
| 3970 | // is either LTE or IWLAN. |
| 3971 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3972 | + "capability."); |
| 3973 | } |
| 3974 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3975 | // There is currently no difference in VT provisioning type. |
| 3976 | return ims.isVtProvisionedOnDevice(); |
| 3977 | } |
| 3978 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3979 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3980 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3981 | } |
| 3982 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3983 | throw new IllegalArgumentException( |
| 3984 | "Tried to get provisioning for MmTel capability '" + capability |
| 3985 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3986 | } |
| 3987 | } |
| 3988 | |
| 3989 | } finally { |
| 3990 | Binder.restoreCallingIdentity(identity); |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | @Override |
| 3995 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3996 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3997 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3998 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3999 | } |
| 4000 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4001 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4002 | return (provisionedBits & capability) > 0; |
| 4003 | } |
| 4004 | |
| 4005 | @Override |
| 4006 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4007 | boolean isProvisioned) { |
| 4008 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4009 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4010 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4011 | } |
| 4012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4013 | "setProvisioningStatusForCapability"); |
| 4014 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4015 | // If the current provisioning status for capability already matches isProvisioned, |
| 4016 | // do nothing. |
| 4017 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4018 | return; |
| 4019 | } |
| 4020 | if (isProvisioned) { |
| 4021 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4022 | } else { |
| 4023 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4024 | } |
| 4025 | } |
| 4026 | |
| 4027 | /** |
| 4028 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4029 | * technology. The bitfield should mirror the bitfield defined by |
| 4030 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4031 | */ |
| 4032 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4033 | String key = getMmTelProvisioningKey(subId, tech); |
| 4034 | // Default is no capabilities are provisioned. |
| 4035 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4036 | } |
| 4037 | |
| 4038 | /** |
| 4039 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4040 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4041 | * technology specified. |
| 4042 | * |
| 4043 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4044 | */ |
| 4045 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4046 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4047 | String key = getMmTelProvisioningKey(subId, tech); |
| 4048 | editor.putInt(key, newField); |
| 4049 | editor.commit(); |
| 4050 | } |
| 4051 | |
| 4052 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4053 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4054 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4055 | } |
| 4056 | |
| 4057 | /** |
| 4058 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4059 | * carrier associated with the subscription id. |
| 4060 | */ |
| 4061 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4062 | int capability) { |
| 4063 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4064 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4065 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4066 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4067 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4068 | false); |
| 4069 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4070 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4071 | |
| 4072 | // First check to make sure that the capability requires provisioning. |
| 4073 | switch (capability) { |
| 4074 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4075 | // intentional fallthrough |
| 4076 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4077 | if (requireVoiceVtProvisioning) { |
| 4078 | // Voice and Video requires provisioning |
| 4079 | return true; |
| 4080 | } |
| 4081 | break; |
| 4082 | } |
| 4083 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4084 | if (requireUtProvisioning) { |
| 4085 | // UT requires provisioning |
| 4086 | return true; |
| 4087 | } |
| 4088 | break; |
| 4089 | } |
| 4090 | } |
| 4091 | return false; |
| 4092 | } |
| 4093 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4094 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4095 | int capability) { |
| 4096 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4097 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4098 | |
| 4099 | boolean requireRcsProvisioning = c.getBoolean( |
| 4100 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4101 | |
| 4102 | // First check to make sure that the capability requires provisioning. |
| 4103 | switch (capability) { |
| 4104 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4105 | // intentional fallthrough |
| 4106 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4107 | if (requireRcsProvisioning) { |
| 4108 | // OPTION or PRESENCE requires provisioning |
| 4109 | return true; |
| 4110 | } |
| 4111 | break; |
| 4112 | } |
| 4113 | } |
| 4114 | return false; |
| 4115 | } |
| 4116 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4117 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4118 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4119 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4120 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4121 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4122 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4123 | final long identity = Binder.clearCallingIdentity(); |
| 4124 | try { |
| 4125 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4126 | int slotId = getSlotIndex(subId); |
| 4127 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4128 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4129 | + subId + "' for key:" + key); |
| 4130 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4131 | } |
| 4132 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4133 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4134 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4135 | + subId + "' for key:" + key); |
| 4136 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4137 | } finally { |
| 4138 | Binder.restoreCallingIdentity(identity); |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | @Override |
| 4143 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4144 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4145 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4146 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4147 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4148 | final long identity = Binder.clearCallingIdentity(); |
| 4149 | try { |
| 4150 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4151 | int slotId = getSlotIndex(subId); |
| 4152 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4153 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4154 | + subId + "' for key:" + key); |
| 4155 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4156 | } |
| 4157 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4158 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4159 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4160 | + subId + "' for key:" + key); |
| 4161 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4162 | } finally { |
| 4163 | Binder.restoreCallingIdentity(identity); |
| 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | @Override |
| 4168 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4169 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4170 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4171 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4173 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4174 | final long identity = Binder.clearCallingIdentity(); |
| 4175 | try { |
| 4176 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4177 | int slotId = getSlotIndex(subId); |
| 4178 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4179 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4180 | + subId + "' for key:" + key); |
| 4181 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4182 | } |
| 4183 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4184 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4185 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4186 | + "' for key:" + key); |
| 4187 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4188 | } finally { |
| 4189 | Binder.restoreCallingIdentity(identity); |
| 4190 | } |
| 4191 | } |
| 4192 | |
| 4193 | @Override |
| 4194 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4195 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4196 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4197 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4198 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4199 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4200 | final long identity = Binder.clearCallingIdentity(); |
| 4201 | try { |
| 4202 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4203 | int slotId = getSlotIndex(subId); |
| 4204 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4205 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4206 | + subId + "' for key:" + key); |
| 4207 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4208 | } |
| 4209 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4210 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4211 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4212 | + "' for key:" + key); |
| 4213 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(identity); |
| 4216 | } |
| 4217 | } |
| 4218 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4219 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4220 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4221 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4222 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4223 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4224 | } |
| 4225 | return slotId; |
| 4226 | } |
| 4227 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4228 | private int getSlotIndex(int subId) { |
| 4229 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4230 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4231 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4232 | } |
| 4233 | return slotId; |
| 4234 | } |
| 4235 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4236 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4237 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4238 | */ |
| 4239 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4240 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4241 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4242 | final int targetSdk = getTargetSdk(callingPackage); |
| 4243 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4244 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4245 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4246 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4247 | mApp, subId, callingPackage, callingFeatureId, |
| 4248 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4249 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4250 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 | final long identity = Binder.clearCallingIdentity(); |
| 4253 | try { |
| 4254 | final Phone phone = getPhone(subId); |
| 4255 | if (phone != null) { |
| 4256 | return phone.getServiceState().getDataNetworkType(); |
| 4257 | } else { |
| 4258 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4259 | } |
| 4260 | } finally { |
| 4261 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | /** |
| 4266 | * Returns the data network type |
| 4267 | */ |
| 4268 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4269 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4270 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4271 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | /** |
| 4275 | * Returns the data network type for a subId |
| 4276 | */ |
| 4277 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4278 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4279 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4280 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4281 | mApp, subId, callingPackage, callingFeatureId, |
| 4282 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4283 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4284 | } |
| 4285 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4286 | final long identity = Binder.clearCallingIdentity(); |
| 4287 | try { |
| 4288 | final Phone phone = getPhone(subId); |
| 4289 | if (phone != null) { |
| 4290 | return phone.getServiceState().getDataNetworkType(); |
| 4291 | } else { |
| 4292 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4293 | } |
| 4294 | } finally { |
| 4295 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4296 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4300 | * Returns the Voice network type for a subId |
| 4301 | */ |
| 4302 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4303 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4304 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4306 | mApp, subId, callingPackage, callingFeatureId, |
| 4307 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4308 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4309 | } |
| 4310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4311 | final long identity = Binder.clearCallingIdentity(); |
| 4312 | try { |
| 4313 | final Phone phone = getPhone(subId); |
| 4314 | if (phone != null) { |
| 4315 | return phone.getServiceState().getVoiceNetworkType(); |
| 4316 | } else { |
| 4317 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4318 | } |
| 4319 | } finally { |
| 4320 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4321 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | /** |
| 4325 | * @return true if a ICC card is present |
| 4326 | */ |
| 4327 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4328 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4329 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4330 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4334 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4335 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4336 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4337 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4338 | final long identity = Binder.clearCallingIdentity(); |
| 4339 | try { |
| 4340 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4341 | if (phone != null) { |
| 4342 | return phone.getIccCard().hasIccCard(); |
| 4343 | } else { |
| 4344 | return false; |
| 4345 | } |
| 4346 | } finally { |
| 4347 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | /** |
| 4352 | * Return if the current radio is LTE on CDMA. This |
| 4353 | * is a tri-state return value as for a period of time |
| 4354 | * the mode may be unknown. |
| 4355 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4356 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4357 | * @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] | 4358 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4359 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4360 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4361 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4362 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4363 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4364 | } |
| 4365 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4366 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4367 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4368 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4369 | try { |
| 4370 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4371 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4372 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4373 | } |
| 4374 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4375 | final long identity = Binder.clearCallingIdentity(); |
| 4376 | try { |
| 4377 | final Phone phone = getPhone(subId); |
| 4378 | if (phone == null) { |
| 4379 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4380 | } else { |
| 4381 | return phone.getLteOnCdmaMode(); |
| 4382 | } |
| 4383 | } finally { |
| 4384 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4385 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4386 | } |
| 4387 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4388 | /** |
| 4389 | * {@hide} |
| 4390 | * Returns Default subId, 0 in the case of single standby. |
| 4391 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4392 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4393 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4394 | } |
| 4395 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4396 | private int getSlotForDefaultSubscription() { |
| 4397 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4398 | } |
| 4399 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4400 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4401 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4402 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4403 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4404 | private boolean isActiveSubscription(int subId) { |
| 4405 | return mSubscriptionController.isActiveSubId(subId); |
| 4406 | } |
| 4407 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4408 | /** |
| 4409 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4410 | */ |
| 4411 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4414 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4415 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4416 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4417 | } finally { |
| 4418 | Binder.restoreCallingIdentity(identity); |
| 4419 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | /** |
| 4423 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4424 | */ |
| 4425 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4426 | final long identity = Binder.clearCallingIdentity(); |
| 4427 | try { |
| 4428 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4429 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4430 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4431 | } finally { |
| 4432 | Binder.restoreCallingIdentity(identity); |
| 4433 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4434 | } |
| 4435 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4436 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4437 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4438 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4439 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4440 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4441 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4442 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4443 | if (phoneId == -1) { |
| 4444 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4445 | + " does not correspond to an active phone"); |
| 4446 | } |
| 4447 | return PhoneFactory.getPhone(phoneId); |
| 4448 | } |
| 4449 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4450 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4451 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4452 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4453 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4454 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4455 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4456 | if (DBG) { |
| 4457 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4458 | } |
| 4459 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4460 | p2); |
| 4461 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4462 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4463 | |
| 4464 | @Override |
| 4465 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4466 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4467 | enforceModifyPermission(); |
| 4468 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4469 | if (DBG) { |
| 4470 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4471 | } |
| 4472 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4473 | callingPackage, aid, p2); |
| 4474 | } |
| 4475 | |
| 4476 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4477 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
| 4480 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4481 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4482 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4483 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4484 | if (bestComponent == null |
| 4485 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4486 | loge("The calling package is not allowed to access ISD-R."); |
| 4487 | throw new SecurityException( |
| 4488 | "The calling package is not allowed to access ISD-R."); |
| 4489 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4490 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4491 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4492 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4493 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4494 | null /* workSource */); |
| 4495 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | return response; |
| 4497 | } finally { |
| 4498 | Binder.restoreCallingIdentity(identity); |
| 4499 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
| 4502 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4503 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4504 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4505 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4506 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4507 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4508 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4509 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4510 | @Override |
| 4511 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4512 | enforceModifyPermission(); |
| 4513 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4514 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4515 | channel); |
| 4516 | } |
| 4517 | |
| 4518 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4519 | final long identity = Binder.clearCallingIdentity(); |
| 4520 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4521 | if (channel < 0) { |
| 4522 | return false; |
| 4523 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4524 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4525 | null /* workSource */); |
| 4526 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4527 | return success; |
| 4528 | } finally { |
| 4529 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4530 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4534 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4535 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4536 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4537 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4538 | if (DBG) { |
| 4539 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4540 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4541 | + p3 + " data=" + data); |
| 4542 | } |
| 4543 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4544 | command, p1, p2, p3, data); |
| 4545 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4546 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4547 | @Override |
| 4548 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4549 | int command, int p1, int p2, int p3, String data) { |
| 4550 | enforceModifyPermission(); |
| 4551 | if (DBG) { |
| 4552 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4553 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4554 | + p3 + " data=" + data); |
| 4555 | } |
| 4556 | return iccTransmitApduLogicalChannelWithPermission( |
| 4557 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4558 | data); |
| 4559 | } |
| 4560 | |
| 4561 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4562 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4563 | final long identity = Binder.clearCallingIdentity(); |
| 4564 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4565 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4566 | return ""; |
| 4567 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4568 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4569 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4570 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4571 | null /* workSource */); |
| 4572 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4573 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4574 | // Append the returned status code to the end of the response payload. |
| 4575 | String s = Integer.toHexString( |
| 4576 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4577 | if (response.payload != null) { |
| 4578 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4579 | } |
| 4580 | return s; |
| 4581 | } finally { |
| 4582 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4583 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4584 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4585 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4586 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4587 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4588 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4590 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4591 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4592 | if (DBG) { |
| 4593 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4594 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4595 | } |
| 4596 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4597 | cla, command, p1, p2, p3, data); |
| 4598 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4599 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4600 | @Override |
| 4601 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4602 | int command, int p1, int p2, int p3, String data) { |
| 4603 | enforceModifyPermission(); |
| 4604 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4605 | if (DBG) { |
| 4606 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4607 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4608 | + " data=" + data); |
| 4609 | } |
| 4610 | |
| 4611 | return iccTransmitApduBasicChannelWithPermission( |
| 4612 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4613 | p2, p3, data); |
| 4614 | } |
| 4615 | |
| 4616 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4617 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4618 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4619 | final long identity = Binder.clearCallingIdentity(); |
| 4620 | try { |
| 4621 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4622 | && TextUtils.equals(ISDR_AID, data)) { |
| 4623 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4624 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4625 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4626 | if (bestComponent == null |
| 4627 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4628 | loge("The calling package is not allowed to select ISD-R."); |
| 4629 | throw new SecurityException( |
| 4630 | "The calling package is not allowed to select ISD-R."); |
| 4631 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4632 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4633 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4634 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4635 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4636 | null /* workSource */); |
| 4637 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4638 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4639 | // Append the returned status code to the end of the response payload. |
| 4640 | String s = Integer.toHexString( |
| 4641 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4642 | if (response.payload != null) { |
| 4643 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4644 | } |
| 4645 | return s; |
| 4646 | } finally { |
| 4647 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4648 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4652 | 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] | 4653 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4654 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4655 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4656 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4657 | final long identity = Binder.clearCallingIdentity(); |
| 4658 | try { |
| 4659 | if (DBG) { |
| 4660 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4661 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4662 | } |
| 4663 | |
| 4664 | IccIoResult response = |
| 4665 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4666 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4667 | subId); |
| 4668 | |
| 4669 | if (DBG) { |
| 4670 | log("Exchange SIM_IO [R]" + response); |
| 4671 | } |
| 4672 | |
| 4673 | byte[] result = null; |
| 4674 | int length = 2; |
| 4675 | if (response.payload != null) { |
| 4676 | length = 2 + response.payload.length; |
| 4677 | result = new byte[length]; |
| 4678 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4679 | } else { |
| 4680 | result = new byte[length]; |
| 4681 | } |
| 4682 | |
| 4683 | result[length - 1] = (byte) response.sw2; |
| 4684 | result[length - 2] = (byte) response.sw1; |
| 4685 | return result; |
| 4686 | } finally { |
| 4687 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4688 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4691 | /** |
| 4692 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4693 | * on a particular subscription |
| 4694 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4695 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4696 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4697 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4698 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4699 | return null; |
| 4700 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4701 | |
| 4702 | final long identity = Binder.clearCallingIdentity(); |
| 4703 | try { |
| 4704 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4705 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4706 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4707 | return null; |
| 4708 | } |
| 4709 | Object response = sendRequest( |
| 4710 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4711 | if (response instanceof String[]) { |
| 4712 | return (String[]) response; |
| 4713 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4714 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4715 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4716 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4717 | } finally { |
| 4718 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4719 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4720 | } |
| 4721 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4722 | /** |
| 4723 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4724 | * subscription. |
| 4725 | * |
| 4726 | * @param subId the id of the subscription. |
| 4727 | * @param appType the uicc app type, must be USIM or SIM. |
| 4728 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4729 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4730 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4731 | * @return number of fplmns that is successfully written to the SIM. |
| 4732 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4733 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4734 | String callingFeatureId) { |
| 4735 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4736 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4737 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4738 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4739 | } |
| 4740 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4741 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4742 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4743 | } |
| 4744 | if (fplmns == null) { |
| 4745 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4746 | } |
| 4747 | for (String fplmn : fplmns) { |
| 4748 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4749 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4750 | } |
| 4751 | } |
| 4752 | final long identity = Binder.clearCallingIdentity(); |
| 4753 | try { |
| 4754 | Object response = sendRequest( |
| 4755 | CMD_SET_FORBIDDEN_PLMNS, |
| 4756 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4757 | subId); |
| 4758 | return (int) response; |
| 4759 | } finally { |
| 4760 | Binder.restoreCallingIdentity(identity); |
| 4761 | } |
| 4762 | } |
| 4763 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4764 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4765 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4767 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4768 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | final long identity = Binder.clearCallingIdentity(); |
| 4770 | try { |
| 4771 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4772 | if (response.payload == null) { |
| 4773 | return ""; |
| 4774 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4775 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4776 | // Append the returned status code to the end of the response payload. |
| 4777 | String s = Integer.toHexString( |
| 4778 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4779 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4780 | return s; |
| 4781 | } finally { |
| 4782 | Binder.restoreCallingIdentity(identity); |
| 4783 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4784 | } |
| 4785 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4786 | /** |
| 4787 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4788 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4789 | * |
| 4790 | * @param itemID the ID of the item to read |
| 4791 | * @return the NV item as a String, or null on error. |
| 4792 | */ |
| 4793 | @Override |
| 4794 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4795 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4796 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4797 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4798 | |
| 4799 | final long identity = Binder.clearCallingIdentity(); |
| 4800 | try { |
| 4801 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4802 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4803 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4804 | return value; |
| 4805 | } finally { |
| 4806 | Binder.restoreCallingIdentity(identity); |
| 4807 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | /** |
| 4811 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4812 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4813 | * |
| 4814 | * @param itemID the ID of the item to read |
| 4815 | * @param itemValue the value to write, as a String |
| 4816 | * @return true on success; false on any failure |
| 4817 | */ |
| 4818 | @Override |
| 4819 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4820 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4822 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4823 | |
| 4824 | final long identity = Binder.clearCallingIdentity(); |
| 4825 | try { |
| 4826 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4827 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4828 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4829 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4830 | return success; |
| 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(identity); |
| 4833 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | /** |
| 4837 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4838 | * Used for device configuration by some CDMA operators. |
| 4839 | * |
| 4840 | * @param preferredRoamingList byte array containing the new PRL |
| 4841 | * @return true on success; false on any failure |
| 4842 | */ |
| 4843 | @Override |
| 4844 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4846 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4847 | |
| 4848 | final long identity = Binder.clearCallingIdentity(); |
| 4849 | try { |
| 4850 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4851 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4852 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4853 | return success; |
| 4854 | } finally { |
| 4855 | Binder.restoreCallingIdentity(identity); |
| 4856 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4857 | } |
| 4858 | |
| 4859 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4860 | * 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] | 4861 | * Used for device configuration by some CDMA operators. |
| 4862 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4863 | * @param slotIndex - device slot. |
| 4864 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4865 | * @return true on success; false on any failure |
| 4866 | */ |
| 4867 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4868 | public boolean resetModemConfig(int slotIndex) { |
| 4869 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4870 | if (phone != null) { |
| 4871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4872 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4873 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4874 | final long identity = Binder.clearCallingIdentity(); |
| 4875 | try { |
| 4876 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4877 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4878 | return success; |
| 4879 | } finally { |
| 4880 | Binder.restoreCallingIdentity(identity); |
| 4881 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4882 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4883 | return false; |
| 4884 | } |
| 4885 | |
| 4886 | /** |
| 4887 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4888 | * |
| 4889 | * @param slotIndex - device slot. |
| 4890 | * |
| 4891 | * @return true on success; false on any failure |
| 4892 | */ |
| 4893 | @Override |
| 4894 | public boolean rebootModem(int slotIndex) { |
| 4895 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4896 | if (phone != null) { |
| 4897 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4898 | mApp, phone.getSubId(), "rebootModem"); |
| 4899 | |
| 4900 | final long identity = Binder.clearCallingIdentity(); |
| 4901 | try { |
| 4902 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4903 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4904 | return success; |
| 4905 | } finally { |
| 4906 | Binder.restoreCallingIdentity(identity); |
| 4907 | } |
| 4908 | } |
| 4909 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4910 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4911 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4912 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4913 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4914 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4915 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4916 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4917 | return new String[0]; |
| 4918 | } |
| 4919 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4920 | final long identity = Binder.clearCallingIdentity(); |
| 4921 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4922 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4923 | } finally { |
| 4924 | Binder.restoreCallingIdentity(identity); |
| 4925 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4928 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4929 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4930 | * {@link #disableIms(int)}. |
| 4931 | * @param slotIndex device slot. |
| 4932 | */ |
| 4933 | public void resetIms(int slotIndex) { |
| 4934 | enforceModifyPermission(); |
| 4935 | |
| 4936 | final long identity = Binder.clearCallingIdentity(); |
| 4937 | try { |
| 4938 | if (mImsResolver == null) { |
| 4939 | // may happen if the does not support IMS. |
| 4940 | return; |
| 4941 | } |
| 4942 | mImsResolver.disableIms(slotIndex); |
| 4943 | mImsResolver.enableIms(slotIndex); |
| 4944 | } finally { |
| 4945 | Binder.restoreCallingIdentity(identity); |
| 4946 | } |
| 4947 | } |
| 4948 | |
| 4949 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4950 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4951 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4952 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4953 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4954 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4955 | |
| 4956 | final long identity = Binder.clearCallingIdentity(); |
| 4957 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4958 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4959 | // may happen if the device does not support IMS. |
| 4960 | return; |
| 4961 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4962 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4963 | } finally { |
| 4964 | Binder.restoreCallingIdentity(identity); |
| 4965 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4969 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4970 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4971 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4972 | public void disableIms(int slotId) { |
| 4973 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4974 | |
| 4975 | final long identity = Binder.clearCallingIdentity(); |
| 4976 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4977 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4978 | // may happen if the device does not support IMS. |
| 4979 | return; |
| 4980 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4981 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4982 | } finally { |
| 4983 | Binder.restoreCallingIdentity(identity); |
| 4984 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | /** |
| 4988 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4989 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4990 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4991 | */ |
| 4992 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4993 | IImsServiceFeatureCallback callback) { |
| 4994 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4995 | |
| 4996 | final long identity = Binder.clearCallingIdentity(); |
| 4997 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4998 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4999 | // may happen if the device does not support IMS. |
| 5000 | return null; |
| 5001 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5002 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | } finally { |
| 5004 | Binder.restoreCallingIdentity(identity); |
| 5005 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | /** |
| 5009 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 5010 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 5011 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 5012 | * listener for feature updates. |
| 5013 | */ |
| 5014 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 5015 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5016 | |
| 5017 | final long identity = Binder.clearCallingIdentity(); |
| 5018 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5019 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5020 | // may happen if the device does not support IMS. |
| 5021 | return null; |
| 5022 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5023 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
| 5026 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5027 | } |
| 5028 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5029 | /** |
| 5030 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5031 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5032 | */ |
| 5033 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5034 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5035 | |
| 5036 | final long identity = Binder.clearCallingIdentity(); |
| 5037 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5038 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5039 | // may happen if the device does not support IMS. |
| 5040 | return null; |
| 5041 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5042 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5043 | } finally { |
| 5044 | Binder.restoreCallingIdentity(identity); |
| 5045 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5046 | } |
| 5047 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5048 | /** |
| 5049 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5050 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5051 | */ |
| 5052 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5053 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | |
| 5055 | final long identity = Binder.clearCallingIdentity(); |
| 5056 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5057 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5058 | // may happen if the device does not support IMS. |
| 5059 | return null; |
| 5060 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5061 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5062 | } finally { |
| 5063 | Binder.restoreCallingIdentity(identity); |
| 5064 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5065 | } |
| 5066 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5067 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5068 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5069 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5070 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5071 | * @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] | 5072 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5073 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5074 | * @param packageName The name of the package that the current configuration will be replaced |
| 5075 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5076 | * @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] | 5077 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5078 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5079 | int[] featureTypes, String packageName) { |
| 5080 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5081 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5082 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5083 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5084 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5085 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5086 | final long identity = Binder.clearCallingIdentity(); |
| 5087 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5088 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5089 | // may happen if the device does not support IMS. |
| 5090 | return false; |
| 5091 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5092 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5093 | for (int featureType : featureTypes) { |
| 5094 | featureConfig.put(featureType, packageName); |
| 5095 | } |
| 5096 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5097 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | } finally { |
| 5099 | Binder.restoreCallingIdentity(identity); |
| 5100 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5104 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5105 | * |
| 5106 | * @param slotId The slot that the ImsService is associated with. |
| 5107 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5108 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5109 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5110 | * @return the package name of the ImsService configuration. |
| 5111 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5112 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5113 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5114 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5115 | TelephonyPermissions |
| 5116 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5117 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5118 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5119 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5120 | final long identity = Binder.clearCallingIdentity(); |
| 5121 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5122 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5123 | // may happen if the device does not support IMS. |
| 5124 | return ""; |
| 5125 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5126 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5127 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5128 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5129 | } finally { |
| 5130 | Binder.restoreCallingIdentity(identity); |
| 5131 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5134 | /** |
| 5135 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5136 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5137 | * @param callback A callback with an integer containing the |
| 5138 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5139 | */ |
| 5140 | @Override |
| 5141 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5142 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5143 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5144 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5145 | "IMS not available on device."); |
| 5146 | } |
| 5147 | final long token = Binder.clearCallingIdentity(); |
| 5148 | try { |
| 5149 | int slotId = getSlotIndex(subId); |
| 5150 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5151 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5152 | + subId + "'"); |
| 5153 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5154 | } |
| 5155 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5156 | try { |
| 5157 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5158 | } catch (RemoteException e) { |
| 5159 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5160 | + "Ignore"); |
| 5161 | } |
| 5162 | }); |
| 5163 | } finally { |
| 5164 | Binder.restoreCallingIdentity(token); |
| 5165 | } |
| 5166 | } |
| 5167 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5168 | public void setImsRegistrationState(boolean registered) { |
| 5169 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5170 | |
| 5171 | final long identity = Binder.clearCallingIdentity(); |
| 5172 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5173 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
| 5176 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5180 | * Set the network selection mode to automatic. |
| 5181 | * |
| 5182 | */ |
| 5183 | @Override |
| 5184 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5185 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5186 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | |
| 5188 | final long identity = Binder.clearCallingIdentity(); |
| 5189 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5190 | if (!isActiveSubscription(subId)) { |
| 5191 | return; |
| 5192 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5194 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5195 | } finally { |
| 5196 | Binder.restoreCallingIdentity(identity); |
| 5197 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5198 | } |
| 5199 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5200 | /** |
| 5201 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5202 | * |
| 5203 | * @param subId the id of the subscription. |
| 5204 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5205 | * the operator to attach to. |
| 5206 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5207 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5208 | * normal network selection next time. |
| 5209 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5210 | */ |
| 5211 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5212 | public boolean setNetworkSelectionModeManual( |
| 5213 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5214 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5215 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5216 | |
| 5217 | if (!isActiveSubscription(subId)) { |
| 5218 | return false; |
| 5219 | } |
| 5220 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5223 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5225 | if (DBG) { |
| 5226 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5227 | + " operator: " + operatorInfo); |
| 5228 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5229 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5230 | } finally { |
| 5231 | Binder.restoreCallingIdentity(identity); |
| 5232 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5233 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5234 | /** |
| 5235 | * Get the manual network selection |
| 5236 | * |
| 5237 | * @param subId the id of the subscription. |
| 5238 | * |
| 5239 | * @return the previously saved user selected PLMN |
| 5240 | */ |
| 5241 | @Override |
| 5242 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5243 | TelephonyPermissions |
| 5244 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5245 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5246 | |
| 5247 | final long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
| 5249 | if (!isActiveSubscription(subId)) { |
| 5250 | return ""; |
| 5251 | } |
| 5252 | |
| 5253 | final Phone phone = getPhone(subId); |
| 5254 | if (phone == null) { |
| 5255 | return ""; |
| 5256 | } |
| 5257 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5258 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5259 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5260 | } finally { |
| 5261 | Binder.restoreCallingIdentity(identity); |
| 5262 | } |
| 5263 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5264 | |
| 5265 | /** |
| 5266 | * Scans for available networks. |
| 5267 | */ |
| 5268 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5269 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5270 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5271 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5272 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5273 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5274 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5275 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5276 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5277 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5278 | .setCallingPid(Binder.getCallingPid()) |
| 5279 | .setCallingUid(Binder.getCallingUid()) |
| 5280 | .setMethod("getCellNetworkScanResults") |
| 5281 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5282 | .build()); |
| 5283 | switch (locationResult) { |
| 5284 | case DENIED_HARD: |
| 5285 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5286 | case DENIED_SOFT: |
| 5287 | return null; |
| 5288 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5290 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5291 | try { |
| 5292 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5293 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5295 | } finally { |
| 5296 | Binder.restoreCallingIdentity(identity); |
| 5297 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
| 5300 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5301 | * Get the call forwarding info, given the call forwarding reason. |
| 5302 | */ |
| 5303 | @Override |
| 5304 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5305 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5306 | long identity = Binder.clearCallingIdentity(); |
| 5307 | try { |
| 5308 | if (DBG) { |
| 5309 | log("getCallForwarding: subId " + subId |
| 5310 | + " callForwardingReason" + callForwardingReason); |
| 5311 | } |
| 5312 | return (CallForwardingInfo) sendRequest( |
| 5313 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5314 | } finally { |
| 5315 | Binder.restoreCallingIdentity(identity); |
| 5316 | } |
| 5317 | } |
| 5318 | |
| 5319 | /** |
| 5320 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5321 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5322 | */ |
| 5323 | @Override |
| 5324 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5325 | enforceModifyPermission(); |
| 5326 | long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
| 5328 | if (DBG) { |
| 5329 | log("setCallForwarding: subId " + subId |
| 5330 | + " callForwardingInfo" + callForwardingInfo); |
| 5331 | } |
| 5332 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5333 | } finally { |
| 5334 | Binder.restoreCallingIdentity(identity); |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | /** |
| 5339 | * Get the call forwarding info, given the call forwarding reason. |
| 5340 | */ |
| 5341 | @Override |
| 5342 | public int getCallWaitingStatus(int subId) { |
| 5343 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5344 | long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
| 5346 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5347 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5348 | } finally { |
| 5349 | Binder.restoreCallingIdentity(identity); |
| 5350 | } |
| 5351 | } |
| 5352 | |
| 5353 | /** |
| 5354 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5355 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5356 | */ |
| 5357 | @Override |
| 5358 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5359 | enforceModifyPermission(); |
| 5360 | long identity = Binder.clearCallingIdentity(); |
| 5361 | try { |
| 5362 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5363 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5364 | } finally { |
| 5365 | Binder.restoreCallingIdentity(identity); |
| 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5370 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5371 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5372 | * @param subId id of the subscription |
| 5373 | * @param request contains the radio access networks with bands/channels to scan |
| 5374 | * @param messenger callback messenger for scan results or errors |
| 5375 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5376 | * @return the id of the requested scan which can be used to stop the scan. |
| 5377 | */ |
| 5378 | @Override |
| 5379 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5380 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5382 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5383 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5384 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5385 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5386 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5387 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5388 | .setCallingPid(Binder.getCallingPid()) |
| 5389 | .setCallingUid(Binder.getCallingUid()) |
| 5390 | .setMethod("requestNetworkScan") |
| 5391 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5392 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5393 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5394 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5395 | if (e != null) { |
| 5396 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5397 | throw e; |
| 5398 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5399 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5400 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5401 | } |
| 5402 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5404 | int callingUid = Binder.getCallingUid(); |
| 5405 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5406 | final long identity = Binder.clearCallingIdentity(); |
| 5407 | try { |
| 5408 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5409 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5410 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5411 | } finally { |
| 5412 | Binder.restoreCallingIdentity(identity); |
| 5413 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5414 | } |
| 5415 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5416 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5417 | NetworkScanRequest request, int subId) { |
| 5418 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5419 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5420 | boolean hasNetworkScanPermission = |
| 5421 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5422 | == PERMISSION_GRANTED; |
| 5423 | |
| 5424 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5425 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5426 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5430 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5431 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5432 | return new SecurityException("Specific channels must not be" |
| 5433 | + " scanned without location access."); |
| 5434 | } |
| 5435 | } |
| 5436 | } |
| 5437 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5438 | return null; |
| 5439 | } |
| 5440 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5441 | /** |
| 5442 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5443 | * |
| 5444 | * @param subId id of the subscription |
| 5445 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5446 | */ |
| 5447 | @Override |
| 5448 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5449 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5450 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5451 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5452 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5455 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5456 | } finally { |
| 5457 | Binder.restoreCallingIdentity(identity); |
| 5458 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5462 | * Get the calculated preferred network type. |
| 5463 | * Used for debugging incorrect network type. |
| 5464 | * |
| 5465 | * @return the preferred network type, defined in RILConstants.java. |
| 5466 | */ |
| 5467 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5468 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5469 | final Phone defaultPhone = getDefaultPhone(); |
| 5470 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5471 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5472 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5473 | } |
| 5474 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | final long identity = Binder.clearCallingIdentity(); |
| 5476 | try { |
| 5477 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5478 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5479 | } finally { |
| 5480 | Binder.restoreCallingIdentity(identity); |
| 5481 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5485 | * Get the preferred network type. |
| 5486 | * Used for device configuration by some CDMA operators. |
| 5487 | * |
| 5488 | * @return the preferred network type, defined in RILConstants.java. |
| 5489 | */ |
| 5490 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5491 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5492 | TelephonyPermissions |
| 5493 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5494 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5495 | |
| 5496 | final long identity = Binder.clearCallingIdentity(); |
| 5497 | try { |
| 5498 | if (DBG) log("getPreferredNetworkType"); |
| 5499 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5500 | int networkType = (result != null ? result[0] : -1); |
| 5501 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5502 | return networkType; |
| 5503 | } finally { |
| 5504 | Binder.restoreCallingIdentity(identity); |
| 5505 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5506 | } |
| 5507 | |
| 5508 | /** |
| 5509 | * Set the preferred network type. |
| 5510 | * Used for device configuration by some CDMA operators. |
| 5511 | * |
| 5512 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5513 | * @return true on success; false on any failure. |
| 5514 | */ |
| 5515 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5516 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5517 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5518 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5519 | |
| 5520 | final long identity = Binder.clearCallingIdentity(); |
| 5521 | try { |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5522 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5523 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5524 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | } finally { |
| 5526 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5527 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5528 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5529 | |
| 5530 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5531 | * Get the allowed network types that store in the telephony provider. |
| 5532 | * |
| 5533 | * @param subId the id of the subscription. |
| 5534 | * @return allowedNetworkTypes the allowed network types. |
| 5535 | */ |
| 5536 | @Override |
| 5537 | public long getAllowedNetworkTypes(int subId) { |
| 5538 | TelephonyPermissions |
| 5539 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5540 | mApp, subId, "getAllowedNetworkTypes"); |
| 5541 | |
| 5542 | final long identity = Binder.clearCallingIdentity(); |
| 5543 | try { |
| 5544 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5545 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5546 | } finally { |
| 5547 | Binder.restoreCallingIdentity(identity); |
| 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | /** |
| 5552 | * Set the allowed network types. |
| 5553 | * |
| 5554 | * @param subId the id of the subscription. |
| 5555 | * @param allowedNetworkTypes the allowed network types. |
| 5556 | * @return true on success; false on any failure. |
| 5557 | */ |
| 5558 | @Override |
| 5559 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5561 | mApp, subId, "setAllowedNetworkTypes"); |
| 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
| 5564 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5565 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5566 | String.valueOf(allowedNetworkTypes)); |
| 5567 | return setPreferredNetworkTypesInternal(subId); |
| 5568 | } finally { |
| 5569 | Binder.restoreCallingIdentity(identity); |
| 5570 | } |
| 5571 | } |
| 5572 | |
| 5573 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5574 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5575 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5576 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5577 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5578 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5579 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5580 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5581 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5582 | |
| 5583 | if (DBG) { |
| 5584 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5585 | + " networkTypes " + networkTypeBitMask |
| 5586 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5587 | + " networkMode " + networkMode); |
| 5588 | } |
| 5589 | |
| 5590 | Boolean success = (Boolean) sendRequest( |
| 5591 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5592 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5593 | return success; |
| 5594 | } |
| 5595 | |
| 5596 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5597 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5598 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5599 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5600 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5601 | * @hide |
| 5602 | */ |
| 5603 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5604 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5605 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5606 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5607 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5608 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5609 | if (phone != null) { |
| 5610 | return phone.hasMatchedTetherApnSetting(); |
| 5611 | } else { |
| 5612 | return false; |
| 5613 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5616 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5620 | * Set mobile data enabled |
| 5621 | * Used by the user through settings etc to turn on/off mobile data |
| 5622 | * |
| 5623 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5624 | */ |
| 5625 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5626 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5628 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5629 | |
| 5630 | final long identity = Binder.clearCallingIdentity(); |
| 5631 | try { |
| 5632 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5633 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5634 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5635 | if (phone != null) { |
| 5636 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5637 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5638 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5639 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | } |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5643 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5647 | * Enable or disable always reporting signal strength changes from radio. |
| 5648 | * |
| 5649 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5650 | */ |
| 5651 | @Override |
| 5652 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5653 | enforceModifyPermission(); |
| 5654 | enforceSystemCaller(); |
| 5655 | |
| 5656 | final long identity = Binder.clearCallingIdentity(); |
| 5657 | final Phone phone = getPhone(subId); |
| 5658 | try { |
| 5659 | if (phone != null) { |
| 5660 | if (DBG) { |
| 5661 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5662 | + " isEnable=" + isEnable); |
| 5663 | } |
| 5664 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5665 | } else { |
| 5666 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5667 | + subId); |
| 5668 | } |
| 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
| 5671 | } |
| 5672 | } |
| 5673 | |
| 5674 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5675 | * Get the user enabled state of Mobile Data. |
| 5676 | * |
| 5677 | * TODO: remove and use isUserDataEnabled. |
| 5678 | * This can't be removed now because some vendor codes |
| 5679 | * calls through ITelephony directly while they should |
| 5680 | * use TelephonyManager. |
| 5681 | * |
| 5682 | * @return true on enabled |
| 5683 | */ |
| 5684 | @Override |
| 5685 | public boolean getDataEnabled(int subId) { |
| 5686 | return isUserDataEnabled(subId); |
| 5687 | } |
| 5688 | |
| 5689 | /** |
| 5690 | * Get whether mobile data is enabled per user setting. |
| 5691 | * |
| 5692 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5693 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5694 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5695 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5696 | * |
| 5697 | * @return {@code true} if data is enabled else {@code false} |
| 5698 | */ |
| 5699 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5700 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5701 | try { |
| 5702 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5703 | null); |
| 5704 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5705 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5706 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5707 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5708 | |
| 5709 | final long identity = Binder.clearCallingIdentity(); |
| 5710 | try { |
| 5711 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5712 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5713 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5714 | if (phone != null) { |
| 5715 | boolean retVal = phone.isUserDataEnabled(); |
| 5716 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5717 | return retVal; |
| 5718 | } else { |
| 5719 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5720 | return false; |
| 5721 | } |
| 5722 | } finally { |
| 5723 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5724 | } |
| 5725 | } |
| 5726 | |
| 5727 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5728 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5729 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5730 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5731 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5732 | * @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] | 5733 | */ |
| 5734 | @Override |
| 5735 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5736 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5737 | |
| 5738 | final long identity = Binder.clearCallingIdentity(); |
| 5739 | try { |
| 5740 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5741 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5742 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5743 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5744 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5746 | return retVal; |
| 5747 | } else { |
| 5748 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5749 | return false; |
| 5750 | } |
| 5751 | } finally { |
| 5752 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5753 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5754 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5755 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5756 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5757 | Phone phone) { |
| 5758 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5759 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5760 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5761 | || subController == null) return privilegeFromSim; |
| 5762 | |
| 5763 | int uid = Binder.getCallingUid(); |
| 5764 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5765 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5766 | |
| 5767 | final long identity = Binder.clearCallingIdentity(); |
| 5768 | try { |
| 5769 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5770 | SubscriptionManager subManager = (SubscriptionManager) |
| 5771 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5772 | for (String pkg : packages) { |
| 5773 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5774 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5775 | } |
| 5776 | } |
| 5777 | return privilegeFromSim; |
| 5778 | } finally { |
| 5779 | Binder.restoreCallingIdentity(identity); |
| 5780 | } |
| 5781 | } |
| 5782 | |
| 5783 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5784 | String pkgName) { |
| 5785 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5786 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5787 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5788 | || subController == null) return privilegeFromSim; |
| 5789 | |
| 5790 | final long identity = Binder.clearCallingIdentity(); |
| 5791 | try { |
| 5792 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5793 | SubscriptionManager subManager = (SubscriptionManager) |
| 5794 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5795 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5796 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5797 | } finally { |
| 5798 | Binder.restoreCallingIdentity(identity); |
| 5799 | } |
| 5800 | } |
| 5801 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5802 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5803 | public int getCarrierPrivilegeStatus(int subId) { |
| 5804 | final Phone phone = getPhone(subId); |
| 5805 | if (phone == null) { |
| 5806 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5807 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5808 | } |
| 5809 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5810 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5811 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5812 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5813 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5814 | |
| 5815 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5816 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5817 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5818 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5819 | |
| 5820 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5821 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5822 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5823 | final Phone phone = getPhone(subId); |
| 5824 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5825 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5826 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5827 | } |
| 5828 | UiccProfile profile = |
| 5829 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5830 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5831 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5832 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5833 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5834 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5835 | profile.getCarrierPrivilegeStatusForUid( |
| 5836 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5837 | } |
| 5838 | |
| 5839 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5840 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5841 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5842 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5846 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5847 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5848 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5849 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5850 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5851 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5852 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5853 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5854 | } |
| 5855 | |
| 5856 | @Override |
| 5857 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5858 | if (TextUtils.isEmpty(pkgName)) |
| 5859 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5860 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5861 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5862 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5863 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5864 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5865 | continue; |
| 5866 | } |
| 5867 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5868 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5869 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5870 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5871 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5872 | break; |
| 5873 | } |
| 5874 | } |
| 5875 | |
| 5876 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5877 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5878 | |
| 5879 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5880 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5881 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5882 | loge("phoneId " + phoneId + " is not valid."); |
| 5883 | return null; |
| 5884 | } |
| 5885 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5886 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5887 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5888 | return null ; |
| 5889 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5890 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5891 | } |
| 5892 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5893 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5894 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5895 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5896 | List<String> privilegedPackages = new ArrayList<>(); |
| 5897 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5898 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5899 | // has UICC in that slot. |
| 5900 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5901 | if (card.hasCarrierPrivilegeRules()) { |
| 5902 | if (packages == null) { |
| 5903 | // Only check packages in user 0 for now |
| 5904 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5905 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5906 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5907 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5908 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5909 | } |
| 5910 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5911 | PackageInfo pkgInfo = packages.get(p); |
| 5912 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5913 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5914 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5915 | privilegedPackages.add(pkgInfo.packageName); |
| 5916 | } |
| 5917 | } |
| 5918 | } |
| 5919 | } |
| 5920 | return privilegedPackages; |
| 5921 | } |
| 5922 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5923 | @Override |
| 5924 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5925 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5926 | |
| 5927 | final long identity = Binder.clearCallingIdentity(); |
| 5928 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5929 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5930 | try { |
| 5931 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5932 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5933 | } |
| 5934 | } finally { |
| 5935 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5936 | } |
| 5937 | return privilegedPackages; |
| 5938 | } |
| 5939 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5940 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5941 | final Phone phone = getPhone(subId); |
| 5942 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5943 | if (card == null) { |
| 5944 | loge("getIccId: No UICC"); |
| 5945 | return null; |
| 5946 | } |
| 5947 | String iccId = card.getIccId(); |
| 5948 | if (TextUtils.isEmpty(iccId)) { |
| 5949 | loge("getIccId: ICC ID is null or empty."); |
| 5950 | return null; |
| 5951 | } |
| 5952 | return iccId; |
| 5953 | } |
| 5954 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5955 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5956 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5957 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5958 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5959 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5960 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5961 | final long identity = Binder.clearCallingIdentity(); |
| 5962 | try { |
| 5963 | final String iccId = getIccId(subId); |
| 5964 | final Phone phone = getPhone(subId); |
| 5965 | if (phone == null) { |
| 5966 | return false; |
| 5967 | } |
| 5968 | final String subscriberId = phone.getSubscriberId(); |
| 5969 | |
| 5970 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5971 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5972 | + subscriberId + " to " + number); |
| 5973 | } |
| 5974 | |
| 5975 | if (TextUtils.isEmpty(iccId)) { |
| 5976 | return false; |
| 5977 | } |
| 5978 | |
| 5979 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5980 | |
| 5981 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5982 | if (alphaTag == null) { |
| 5983 | editor.remove(alphaTagPrefKey); |
| 5984 | } else { |
| 5985 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5986 | } |
| 5987 | |
| 5988 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5989 | // track all merged IMSIs based on line number |
| 5990 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5991 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5992 | if (number == null) { |
| 5993 | editor.remove(numberPrefKey); |
| 5994 | editor.remove(subscriberPrefKey); |
| 5995 | } else { |
| 5996 | editor.putString(numberPrefKey, number); |
| 5997 | editor.putString(subscriberPrefKey, subscriberId); |
| 5998 | } |
| 5999 | |
| 6000 | editor.commit(); |
| 6001 | return true; |
| 6002 | } finally { |
| 6003 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6004 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6005 | } |
| 6006 | |
| 6007 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6008 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6009 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6010 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6011 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6012 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6013 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6014 | return null; |
| 6015 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | final long identity = Binder.clearCallingIdentity(); |
| 6018 | try { |
| 6019 | String iccId = getIccId(subId); |
| 6020 | if (iccId != null) { |
| 6021 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6022 | if (DBG_MERGE) { |
| 6023 | log("getLine1NumberForDisplay returning " |
| 6024 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6025 | } |
| 6026 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6027 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6028 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6029 | return null; |
| 6030 | } finally { |
| 6031 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6032 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
| 6035 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6036 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6037 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6038 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6039 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6040 | return null; |
| 6041 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6042 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6043 | final long identity = Binder.clearCallingIdentity(); |
| 6044 | try { |
| 6045 | String iccId = getIccId(subId); |
| 6046 | if (iccId != null) { |
| 6047 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6048 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6049 | } |
| 6050 | return null; |
| 6051 | } finally { |
| 6052 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6053 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6054 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6055 | |
| 6056 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6057 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6058 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6059 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6060 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6061 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6062 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6063 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6064 | return null; |
| 6065 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6066 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6067 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6068 | // the process, where TelephonyManager was instantiated. |
| 6069 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6070 | final long identity = Binder.clearCallingIdentity(); |
| 6071 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6072 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6073 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6074 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6075 | |
| 6076 | // Figure out what subscribers are currently active |
| 6077 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6078 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6079 | // Only consider subs which match the current subId |
| 6080 | // This logic can be simplified. See b/131189269 for progress. |
| 6081 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6082 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6083 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6084 | |
| 6085 | // First pass, find a number override for an active subscriber |
| 6086 | String mergeNumber = null; |
| 6087 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6088 | for (String key : prefs.keySet()) { |
| 6089 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6090 | final String subscriberId = (String) prefs.get(key); |
| 6091 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6092 | final String iccId = key.substring( |
| 6093 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6094 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6095 | mergeNumber = (String) prefs.get(numberKey); |
| 6096 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6097 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6098 | + " for active subscriber " + subscriberId); |
| 6099 | } |
| 6100 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6101 | break; |
| 6102 | } |
| 6103 | } |
| 6104 | } |
| 6105 | } |
| 6106 | |
| 6107 | // Shortcut when no active merged subscribers |
| 6108 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6109 | return null; |
| 6110 | } |
| 6111 | |
| 6112 | // Second pass, find all subscribers under that line override |
| 6113 | final ArraySet<String> result = new ArraySet<>(); |
| 6114 | for (String key : prefs.keySet()) { |
| 6115 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6116 | final String number = (String) prefs.get(key); |
| 6117 | if (mergeNumber.equals(number)) { |
| 6118 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6119 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6120 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6121 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6122 | result.add(subscriberId); |
| 6123 | } |
| 6124 | } |
| 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6129 | Arrays.sort(resultArray); |
| 6130 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6131 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6132 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6133 | } |
| 6134 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6135 | } finally { |
| 6136 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6137 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6138 | } |
| 6139 | |
| 6140 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6141 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6142 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6143 | |
| 6144 | final long identity = Binder.clearCallingIdentity(); |
| 6145 | try { |
| 6146 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6147 | TelephonyManager.class); |
| 6148 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6149 | if (subscriberId == null) { |
| 6150 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6151 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6152 | + subId); |
| 6153 | } |
| 6154 | return null; |
| 6155 | } |
| 6156 | |
| 6157 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6158 | .getSubscriptionInfo(subId); |
| 6159 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6160 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6161 | if (groupUuid == null) { |
| 6162 | return new String[]{subscriberId}; |
| 6163 | } |
| 6164 | |
| 6165 | // Get all subscriberIds from the group. |
| 6166 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6167 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6168 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6169 | mApp.getFeatureId()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6170 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6171 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6172 | if (subscriberId != null) { |
| 6173 | mergedSubscriberIds.add(subscriberId); |
| 6174 | } |
| 6175 | } |
| 6176 | |
| 6177 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(identity); |
| 6180 | |
| 6181 | } |
| 6182 | } |
| 6183 | |
| 6184 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6185 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6186 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6187 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6188 | |
| 6189 | final long identity = Binder.clearCallingIdentity(); |
| 6190 | try { |
| 6191 | final Phone phone = getPhone(subId); |
| 6192 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6193 | } finally { |
| 6194 | Binder.restoreCallingIdentity(identity); |
| 6195 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6196 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6197 | |
| 6198 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6199 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6200 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6201 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6202 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6203 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6204 | |
| 6205 | final long identity = Binder.clearCallingIdentity(); |
| 6206 | try { |
| 6207 | final Phone phone = getPhone(subId); |
| 6208 | if (phone == null) { |
| 6209 | return false; |
| 6210 | } |
| 6211 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6212 | cdmaNonRoamingList); |
| 6213 | } finally { |
| 6214 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6215 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6216 | } |
| 6217 | |
| 6218 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6219 | @Deprecated |
| 6220 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6221 | enforceModifyPermission(); |
| 6222 | |
| 6223 | int returnValue = 0; |
| 6224 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6225 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6226 | if(result.exception == null) { |
| 6227 | if (result.result != null) { |
| 6228 | byte[] responseData = (byte[])(result.result); |
| 6229 | if(responseData.length > oemResp.length) { |
| 6230 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6231 | responseData.length + "bytes. Buffer Size is " + |
| 6232 | oemResp.length + "bytes."); |
| 6233 | } |
| 6234 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6235 | returnValue = responseData.length; |
| 6236 | } |
| 6237 | } else { |
| 6238 | CommandException ex = (CommandException) result.exception; |
| 6239 | returnValue = ex.getCommandError().ordinal(); |
| 6240 | if(returnValue > 0) returnValue *= -1; |
| 6241 | } |
| 6242 | } catch (RuntimeException e) { |
| 6243 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6244 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6245 | if(returnValue > 0) returnValue *= -1; |
| 6246 | } |
| 6247 | |
| 6248 | return returnValue; |
| 6249 | } |
| 6250 | |
| 6251 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6252 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6253 | try { |
| 6254 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6255 | } catch (RuntimeException e) { |
| 6256 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6257 | } |
| 6258 | } |
| 6259 | |
| 6260 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6261 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6262 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6263 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6264 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6265 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6266 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | final long identity = Binder.clearCallingIdentity(); |
| 6268 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6269 | TelephonyPermissions |
| 6270 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6271 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6272 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6273 | } finally { |
| 6274 | Binder.restoreCallingIdentity(identity); |
| 6275 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6276 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6277 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6278 | |
| 6279 | @Override |
| 6280 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6281 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6282 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | |
| 6284 | final long identity = Binder.clearCallingIdentity(); |
| 6285 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6286 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6287 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6288 | } finally { |
| 6289 | Binder.restoreCallingIdentity(identity); |
| 6290 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6291 | } |
| 6292 | |
| 6293 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6294 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6295 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6296 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6297 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6298 | return false; |
| 6299 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6300 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6301 | final long identity = Binder.clearCallingIdentity(); |
| 6302 | try { |
| 6303 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6304 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6305 | // In the long run, we may instead need to check if there exists a connection service |
| 6306 | // which can support video calling. |
| 6307 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6308 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6309 | return imsManager.isVtEnabledByPlatform() |
| 6310 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6311 | && imsManager.isVtEnabledByUser(); |
| 6312 | } finally { |
| 6313 | Binder.restoreCallingIdentity(identity); |
| 6314 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6315 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6316 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6317 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6318 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6319 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6321 | mApp, subId, callingPackage, callingFeatureId, |
| 6322 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6323 | return false; |
| 6324 | } |
| 6325 | |
| 6326 | final long identity = Binder.clearCallingIdentity(); |
| 6327 | try { |
| 6328 | CarrierConfigManager configManager = |
| 6329 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6330 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6331 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6332 | } finally { |
| 6333 | Binder.restoreCallingIdentity(identity); |
| 6334 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6335 | } |
| 6336 | |
| 6337 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6338 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6339 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6340 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6341 | return false; |
| 6342 | } |
| 6343 | |
| 6344 | final long identity = Binder.clearCallingIdentity(); |
| 6345 | try { |
| 6346 | CarrierConfigManager configManager = |
| 6347 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6348 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6349 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6350 | } finally { |
| 6351 | Binder.restoreCallingIdentity(identity); |
| 6352 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6353 | } |
| 6354 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6355 | @Override |
| 6356 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6357 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6358 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6359 | } |
| 6360 | |
| 6361 | @Override |
| 6362 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6363 | final long identity = Binder.clearCallingIdentity(); |
| 6364 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6365 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6366 | } finally { |
| 6367 | Binder.restoreCallingIdentity(identity); |
| 6368 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6369 | } |
| 6370 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6371 | /** |
| 6372 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6373 | * support for the feature and device firmware support. |
| 6374 | * |
| 6375 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6376 | */ |
| 6377 | @Override |
| 6378 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6379 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6380 | final Phone phone = getPhone(subscriptionId); |
| 6381 | if (phone == null) { |
| 6382 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6383 | return false; |
| 6384 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6385 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6386 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6387 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6388 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6389 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6390 | return isCarrierSupported && isDeviceSupported; |
| 6391 | } finally { |
| 6392 | Binder.restoreCallingIdentity(identity); |
| 6393 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6394 | } |
| 6395 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6396 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6397 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6398 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6399 | * 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] | 6400 | */ |
| 6401 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6402 | final long identity = Binder.clearCallingIdentity(); |
| 6403 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6404 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6405 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6406 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6407 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6408 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6409 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | } finally { |
| 6411 | Binder.restoreCallingIdentity(identity); |
| 6412 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6413 | } |
| 6414 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6415 | @Deprecated |
| 6416 | @Override |
| 6417 | public String getDeviceId(String callingPackage) { |
| 6418 | return getDeviceIdWithFeature(callingPackage, null); |
| 6419 | } |
| 6420 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6421 | /** |
| 6422 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6423 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6424 | * |
| 6425 | * <p>Requires Permission: |
| 6426 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6427 | */ |
| 6428 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6429 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6430 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6431 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6432 | return null; |
| 6433 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6434 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6435 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6436 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6437 | return null; |
| 6438 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | |
| 6440 | final long identity = Binder.clearCallingIdentity(); |
| 6441 | try { |
| 6442 | return phone.getDeviceId(); |
| 6443 | } finally { |
| 6444 | Binder.restoreCallingIdentity(identity); |
| 6445 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6446 | } |
| 6447 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6448 | /** |
| 6449 | * {@hide} |
| 6450 | * Returns the IMS Registration Status on a particular subid |
| 6451 | * |
| 6452 | * @param subId |
| 6453 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6454 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6455 | Phone phone = getPhone(subId); |
| 6456 | if (phone != null) { |
| 6457 | return phone.isImsRegistered(); |
| 6458 | } else { |
| 6459 | return false; |
| 6460 | } |
| 6461 | } |
| 6462 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6463 | @Override |
| 6464 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6465 | final long identity = Binder.clearCallingIdentity(); |
| 6466 | try { |
| 6467 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6468 | } finally { |
| 6469 | Binder.restoreCallingIdentity(identity); |
| 6470 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6471 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6472 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6473 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6474 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6475 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6476 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6477 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6478 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6479 | } |
| 6480 | final long identity = Binder.clearCallingIdentity(); |
| 6481 | try { |
| 6482 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6483 | } finally { |
| 6484 | Binder.restoreCallingIdentity(identity); |
| 6485 | } |
| 6486 | } |
| 6487 | |
| 6488 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6489 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6490 | final long identity = Binder.clearCallingIdentity(); |
| 6491 | try { |
| 6492 | Phone phone = getPhone(subscriptionId); |
| 6493 | if (phone == null) { |
| 6494 | return null; |
| 6495 | } |
| 6496 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6497 | } finally { |
| 6498 | Binder.restoreCallingIdentity(identity); |
| 6499 | } |
| 6500 | } |
| 6501 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6502 | /** |
| 6503 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6504 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6505 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6506 | final long identity = Binder.clearCallingIdentity(); |
| 6507 | try { |
| 6508 | Phone phone = getPhone(subId); |
| 6509 | if (phone != null) { |
| 6510 | return phone.isWifiCallingEnabled(); |
| 6511 | } else { |
| 6512 | return false; |
| 6513 | } |
| 6514 | } finally { |
| 6515 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6516 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6517 | } |
| 6518 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6519 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6520 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6521 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6522 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6523 | final long identity = Binder.clearCallingIdentity(); |
| 6524 | try { |
| 6525 | Phone phone = getPhone(subId); |
| 6526 | if (phone != null) { |
| 6527 | return phone.isVideoEnabled(); |
| 6528 | } else { |
| 6529 | return false; |
| 6530 | } |
| 6531 | } finally { |
| 6532 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | /** |
| 6537 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6538 | * defined in {@link ImsRegistrationImplBase}. |
| 6539 | */ |
| 6540 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6541 | final long identity = Binder.clearCallingIdentity(); |
| 6542 | try { |
| 6543 | Phone phone = getPhone(subId); |
| 6544 | if (phone != null) { |
| 6545 | return phone.getImsRegistrationTech(); |
| 6546 | } else { |
| 6547 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6548 | } |
| 6549 | } finally { |
| 6550 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6551 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6552 | } |
| 6553 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6554 | @Override |
| 6555 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6556 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6557 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6558 | return; |
| 6559 | } |
| 6560 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6561 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6562 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6563 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6564 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6565 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6566 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6567 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6568 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6569 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6570 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6571 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6572 | // There has been issues when Sms raw table somehow stores orphan |
| 6573 | // fragments. They lead to garbled message when new fragments come |
| 6574 | // in and combined with those stale ones. In case this happens again, |
| 6575 | // user can reset all network settings which will clean up this table. |
| 6576 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6577 | // Clean up IMS settings as well here. |
| 6578 | int slotId = getSlotIndex(subId); |
| 6579 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6580 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6581 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6582 | |
| 6583 | // Erase modem config if erase modem on network setting is enabled. |
| 6584 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6585 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6586 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6587 | sendEraseModemConfig(getDefaultPhone()); |
| 6588 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6589 | } finally { |
| 6590 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6591 | } |
| 6592 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6593 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6594 | private void cleanUpSmsRawTable(Context context) { |
| 6595 | ContentResolver resolver = context.getContentResolver(); |
| 6596 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6597 | resolver.delete(uri, null, null); |
| 6598 | } |
| 6599 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6600 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6601 | public String getSimLocaleForSubscriber(int subId) { |
| 6602 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6603 | final Phone phone = getPhone(subId); |
| 6604 | if (phone == null) { |
| 6605 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6606 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6607 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6608 | final long identity = Binder.clearCallingIdentity(); |
| 6609 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6610 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6611 | phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6612 | if (info == null) { |
| 6613 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6614 | return null; |
| 6615 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6616 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6617 | // preferences (EF-PL and EF-LI)... |
| 6618 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6619 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6620 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6621 | if (localeFromDefaultSim != null) { |
| 6622 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6623 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6624 | + localeFromDefaultSim); |
| 6625 | return localeFromDefaultSim.toLanguageTag(); |
| 6626 | } else { |
| 6627 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6628 | } |
| 6629 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6630 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6631 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6632 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6633 | // the SIM and carrier preferences does not include a country we add the country |
| 6634 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6635 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6637 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6638 | return mccLocale.toLanguageTag(); |
| 6639 | } |
| 6640 | |
| 6641 | if (DBG) log("No locale found - returning null"); |
| 6642 | return null; |
| 6643 | } finally { |
| 6644 | Binder.restoreCallingIdentity(identity); |
| 6645 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6649 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6650 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6651 | } |
| 6652 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6653 | /** |
| 6654 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6655 | */ |
| 6656 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6657 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6658 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6659 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6660 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6661 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6662 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6663 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6664 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6665 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6666 | * representing the state of the modem. |
| 6667 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6668 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6669 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6670 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6671 | */ |
| 6672 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6673 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6674 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6675 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6676 | |
| 6677 | final long identity = Binder.clearCallingIdentity(); |
| 6678 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame^] | 6679 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6680 | } finally { |
| 6681 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6682 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6683 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6684 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6685 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6686 | // less than total activity duration. |
| 6687 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6688 | if (info == null) { |
| 6689 | return false; |
| 6690 | } |
| 6691 | int activityDurationMs = |
| 6692 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6693 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6694 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6695 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6696 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6697 | } |
| 6698 | return (info.isValid() |
| 6699 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6700 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6701 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6702 | && (totalTxTimeMs <= activityDurationMs)); |
| 6703 | } |
| 6704 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6705 | /** |
| 6706 | * {@hide} |
| 6707 | * Returns the service state information on specified subscription. |
| 6708 | */ |
| 6709 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6710 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6711 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6712 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6713 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6714 | return null; |
| 6715 | } |
| 6716 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6717 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6718 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6719 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6720 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6721 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6722 | .setCallingPid(Binder.getCallingPid()) |
| 6723 | .setCallingUid(Binder.getCallingUid()) |
| 6724 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6725 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6726 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6727 | .build()); |
| 6728 | |
| 6729 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6730 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6731 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6732 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6733 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6734 | .setCallingPid(Binder.getCallingPid()) |
| 6735 | .setCallingUid(Binder.getCallingUid()) |
| 6736 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6737 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6738 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6739 | .build()); |
| 6740 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6741 | boolean hasFinePermission = |
| 6742 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6743 | boolean hasCoarsePermission = |
| 6744 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | final long identity = Binder.clearCallingIdentity(); |
| 6747 | try { |
| 6748 | final Phone phone = getPhone(subId); |
| 6749 | if (phone == null) { |
| 6750 | return null; |
| 6751 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6752 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6753 | ServiceState ss = phone.getServiceState(); |
| 6754 | |
| 6755 | // Scrub out the location info in ServiceState depending on what level of access |
| 6756 | // the caller has. |
| 6757 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6758 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6759 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6760 | } finally { |
| 6761 | Binder.restoreCallingIdentity(identity); |
| 6762 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6763 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6764 | |
| 6765 | /** |
| 6766 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6767 | * |
| 6768 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6769 | * voicemail ringtone. |
| 6770 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6771 | * PhoneAccount. |
| 6772 | */ |
| 6773 | @Override |
| 6774 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6775 | final long identity = Binder.clearCallingIdentity(); |
| 6776 | try { |
| 6777 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6778 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6779 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6781 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6782 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6783 | } finally { |
| 6784 | Binder.restoreCallingIdentity(identity); |
| 6785 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6786 | } |
| 6787 | |
| 6788 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6789 | * Sets the per-account voicemail ringtone. |
| 6790 | * |
| 6791 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6792 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6793 | * |
| 6794 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6795 | * voicemail ringtone. |
| 6796 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6797 | * PhoneAccount. |
| 6798 | */ |
| 6799 | @Override |
| 6800 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6801 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6802 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6803 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6804 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6805 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6806 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6807 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6808 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6809 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6810 | |
| 6811 | final long identity = Binder.clearCallingIdentity(); |
| 6812 | try { |
| 6813 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6814 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6815 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6816 | } |
| 6817 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6818 | } finally { |
| 6819 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6820 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6821 | } |
| 6822 | |
| 6823 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6824 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6825 | * |
| 6826 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6827 | * voicemail vibration setting. |
| 6828 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6829 | */ |
| 6830 | @Override |
| 6831 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6832 | final long identity = Binder.clearCallingIdentity(); |
| 6833 | try { |
| 6834 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6835 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6836 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6837 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6839 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
| 6842 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6843 | } |
| 6844 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6845 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6846 | * Sets the per-account voicemail vibration. |
| 6847 | * |
| 6848 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6849 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6850 | * |
| 6851 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6852 | * voicemail vibration setting. |
| 6853 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6854 | * specific PhoneAccount. |
| 6855 | */ |
| 6856 | @Override |
| 6857 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6858 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6859 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6860 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6861 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6862 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6863 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6864 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6865 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6866 | } |
| 6867 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | final long identity = Binder.clearCallingIdentity(); |
| 6869 | try { |
| 6870 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6871 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6872 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6873 | } |
| 6874 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6875 | } finally { |
| 6876 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6877 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6878 | } |
| 6879 | |
| 6880 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6881 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6882 | * |
| 6883 | * @throws SecurityException if the caller does not have the required permission |
| 6884 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6885 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6886 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6887 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6888 | } |
| 6889 | |
| 6890 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6891 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6892 | * permission. |
| 6893 | * |
| 6894 | * @throws SecurityException if the caller does not have the required permission |
| 6895 | */ |
| 6896 | private void enforceSendSmsPermission() { |
| 6897 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6898 | } |
| 6899 | |
| 6900 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6901 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6902 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6903 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6904 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6905 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6906 | final long identity = Binder.clearCallingIdentity(); |
| 6907 | try { |
| 6908 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6909 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | if (componentName == null) { |
| 6911 | throw new SecurityException( |
| 6912 | "Caller not current active visual voicemail package[null]"); |
| 6913 | } |
| 6914 | String vvmPackage = componentName.getPackageName(); |
| 6915 | if (!callingPackage.equals(vvmPackage)) { |
| 6916 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6917 | + vvmPackage + "]"); |
| 6918 | } |
| 6919 | } finally { |
| 6920 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6921 | } |
| 6922 | } |
| 6923 | |
| 6924 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6925 | * Return the application ID for the app type. |
| 6926 | * |
| 6927 | * @param subId the subscription ID that this request applies to. |
| 6928 | * @param appType the uicc app type. |
| 6929 | * @return Application ID for specificied app type, or null if no uicc. |
| 6930 | */ |
| 6931 | @Override |
| 6932 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6933 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6934 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6935 | |
| 6936 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6937 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6938 | if (phone == null) { |
| 6939 | return null; |
| 6940 | } |
| 6941 | String aid = null; |
| 6942 | try { |
| 6943 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6944 | .getApplicationByType(appType).getAid(); |
| 6945 | } catch (Exception e) { |
| 6946 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6947 | } |
| 6948 | return aid; |
| 6949 | } finally { |
| 6950 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6951 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6952 | } |
| 6953 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6954 | /** |
| 6955 | * Return the Electronic Serial Number. |
| 6956 | * |
| 6957 | * @param subId the subscription ID that this request applies to. |
| 6958 | * @return ESN or null if error. |
| 6959 | */ |
| 6960 | @Override |
| 6961 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6962 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6963 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6964 | |
| 6965 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6966 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6967 | if (phone == null) { |
| 6968 | return null; |
| 6969 | } |
| 6970 | String esn = null; |
| 6971 | try { |
| 6972 | esn = phone.getEsn(); |
| 6973 | } catch (Exception e) { |
| 6974 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6975 | } |
| 6976 | return esn; |
| 6977 | } finally { |
| 6978 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6979 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6982 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6983 | * Return the Preferred Roaming List Version. |
| 6984 | * |
| 6985 | * @param subId the subscription ID that this request applies to. |
| 6986 | * @return PRLVersion or null if error. |
| 6987 | */ |
| 6988 | @Override |
| 6989 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6990 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6991 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6992 | |
| 6993 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6994 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | if (phone == null) { |
| 6996 | return null; |
| 6997 | } |
| 6998 | String cdmaPrlVersion = null; |
| 6999 | try { |
| 7000 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7001 | } catch (Exception e) { |
| 7002 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7003 | } |
| 7004 | return cdmaPrlVersion; |
| 7005 | } finally { |
| 7006 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7007 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7011 | * Get snapshot of Telephony histograms |
| 7012 | * @return List of Telephony histograms |
| 7013 | * @hide |
| 7014 | */ |
| 7015 | @Override |
| 7016 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7018 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | return RIL.getTelephonyRILTimingHistograms(); |
| 7023 | } finally { |
| 7024 | Binder.restoreCallingIdentity(identity); |
| 7025 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7026 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7027 | |
| 7028 | /** |
| 7029 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7030 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7031 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7032 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7033 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7034 | * @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] | 7035 | */ |
| 7036 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7037 | @TelephonyManager.SetCarrierRestrictionResult |
| 7038 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7039 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7040 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7041 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7042 | if (carrierRestrictionRules == null) { |
| 7043 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7044 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7045 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | final long identity = Binder.clearCallingIdentity(); |
| 7047 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7048 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7049 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | } finally { |
| 7051 | Binder.restoreCallingIdentity(identity); |
| 7052 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7053 | } |
| 7054 | |
| 7055 | /** |
| 7056 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7057 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7058 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7059 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7060 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7061 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7062 | */ |
| 7063 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7064 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7065 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7066 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7067 | |
| 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7070 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7071 | if (response instanceof CarrierRestrictionRules) { |
| 7072 | return (CarrierRestrictionRules) response; |
| 7073 | } |
| 7074 | // Response is an Exception of some kind, |
| 7075 | // which is signalled to the user as a NULL retval |
| 7076 | return null; |
| 7077 | } catch (Exception e) { |
| 7078 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7079 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | } finally { |
| 7081 | Binder.restoreCallingIdentity(identity); |
| 7082 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7083 | } |
| 7084 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7085 | /** |
| 7086 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7087 | * @param subId the subscription ID that this action applies to. |
| 7088 | * @param enabled control enable or disable metered apns. |
| 7089 | * {@hide} |
| 7090 | */ |
| 7091 | @Override |
| 7092 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7093 | enforceModifyPermission(); |
| 7094 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7095 | |
| 7096 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7097 | if (phone == null) { |
| 7098 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7099 | return; |
| 7100 | } |
| 7101 | try { |
| 7102 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7103 | } catch (Exception e) { |
| 7104 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7105 | } finally { |
| 7106 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7107 | } |
| 7108 | } |
| 7109 | |
| 7110 | /** |
| 7111 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7112 | * @param subId the subscription ID that this action applies to. |
| 7113 | * @param enabled control enable or disable radio. |
| 7114 | * {@hide} |
| 7115 | */ |
| 7116 | @Override |
| 7117 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7118 | enforceModifyPermission(); |
| 7119 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7120 | |
| 7121 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7122 | if (phone == null) { |
| 7123 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7124 | return; |
| 7125 | } |
| 7126 | try { |
| 7127 | phone.carrierActionSetRadioEnabled(enabled); |
| 7128 | } catch (Exception e) { |
| 7129 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7130 | } finally { |
| 7131 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7132 | } |
| 7133 | } |
| 7134 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7135 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7136 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7137 | * network status based on which carrier apps could apply actions accordingly, |
| 7138 | * enable/disable default url handler for example. |
| 7139 | * |
| 7140 | * @param subId the subscription ID that this action applies to. |
| 7141 | * @param report control start/stop reporting the default network status. |
| 7142 | * {@hide} |
| 7143 | */ |
| 7144 | @Override |
| 7145 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7146 | enforceModifyPermission(); |
| 7147 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7148 | |
| 7149 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7150 | if (phone == null) { |
| 7151 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7152 | return; |
| 7153 | } |
| 7154 | try { |
| 7155 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7156 | } catch (Exception e) { |
| 7157 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7158 | } finally { |
| 7159 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7160 | } |
| 7161 | } |
| 7162 | |
| 7163 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7164 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7165 | * @param subId the subscription ID that this action applies to. |
| 7166 | * {@hide} |
| 7167 | */ |
| 7168 | @Override |
| 7169 | public void carrierActionResetAll(int subId) { |
| 7170 | enforceModifyPermission(); |
| 7171 | final Phone phone = getPhone(subId); |
| 7172 | if (phone == null) { |
| 7173 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7174 | return; |
| 7175 | } |
| 7176 | try { |
| 7177 | phone.carrierActionResetAll(); |
| 7178 | } catch (Exception e) { |
| 7179 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7180 | } |
| 7181 | } |
| 7182 | |
| 7183 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7184 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7185 | * bug report is being generated. |
| 7186 | */ |
| 7187 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7188 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7189 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7190 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7191 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7192 | + Binder.getCallingPid() |
| 7193 | + ", uid=" + Binder.getCallingUid() |
| 7194 | + "without permission " |
| 7195 | + android.Manifest.permission.DUMP); |
| 7196 | return; |
| 7197 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7198 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7199 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7200 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7201 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7202 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7203 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7204 | @NonNull String[] args) { |
| 7205 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7206 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7207 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7208 | } |
| 7209 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7210 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7211 | * Policy control of data connection. Usually used when data limit is passed. |
| 7212 | * @param enabled True if enabling the data, otherwise disabling. |
| 7213 | * @param subId Subscription index |
| 7214 | * {@hide} |
| 7215 | */ |
| 7216 | @Override |
| 7217 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7219 | |
| 7220 | final long identity = Binder.clearCallingIdentity(); |
| 7221 | try { |
| 7222 | Phone phone = getPhone(subId); |
| 7223 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7224 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7225 | } |
| 7226 | } finally { |
| 7227 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7228 | } |
| 7229 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7230 | |
| 7231 | /** |
| 7232 | * Get Client request stats |
| 7233 | * @return List of Client Request Stats |
| 7234 | * @hide |
| 7235 | */ |
| 7236 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7237 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7238 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7239 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7240 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7241 | return null; |
| 7242 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7243 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7244 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7245 | final long identity = Binder.clearCallingIdentity(); |
| 7246 | try { |
| 7247 | if (phone != null) { |
| 7248 | return phone.getClientRequestStats(); |
| 7249 | } |
| 7250 | |
| 7251 | return null; |
| 7252 | } finally { |
| 7253 | Binder.restoreCallingIdentity(identity); |
| 7254 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7255 | } |
| 7256 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7257 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7258 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7259 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7260 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7261 | |
| 7262 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7263 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7264 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7265 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7266 | * @param state State of SIM (power down, power up, pass through) |
| 7267 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7268 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7269 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7270 | * |
| 7271 | **/ |
| 7272 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7273 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7274 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7275 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7276 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7277 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7278 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7279 | final long identity = Binder.clearCallingIdentity(); |
| 7280 | try { |
| 7281 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7282 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7283 | } |
| 7284 | } finally { |
| 7285 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7286 | } |
| 7287 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7288 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7289 | private boolean isUssdApiAllowed(int subId) { |
| 7290 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7291 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7292 | if (configManager == null) { |
| 7293 | return false; |
| 7294 | } |
| 7295 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7296 | if (pb == null) { |
| 7297 | return false; |
| 7298 | } |
| 7299 | return pb.getBoolean( |
| 7300 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7301 | } |
| 7302 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7303 | /** |
| 7304 | * Check if phone is in emergency callback mode |
| 7305 | * @return true if phone is in emergency callback mode |
| 7306 | * @param subId sub id |
| 7307 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7308 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7309 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7310 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7311 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7312 | |
| 7313 | final long identity = Binder.clearCallingIdentity(); |
| 7314 | try { |
| 7315 | if (phone != null) { |
| 7316 | return phone.isInEcm(); |
| 7317 | } else { |
| 7318 | return false; |
| 7319 | } |
| 7320 | } finally { |
| 7321 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7322 | } |
| 7323 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7324 | |
| 7325 | /** |
| 7326 | * Get the current signal strength information for the given subscription. |
| 7327 | * Because this information is not updated when the device is in a low power state |
| 7328 | * it should not be relied-upon to be current. |
| 7329 | * @param subId Subscription index |
| 7330 | * @return the most recent cached signal strength info from the modem |
| 7331 | */ |
| 7332 | @Override |
| 7333 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7334 | final long identity = Binder.clearCallingIdentity(); |
| 7335 | try { |
| 7336 | Phone p = getPhone(subId); |
| 7337 | if (p == null) { |
| 7338 | return null; |
| 7339 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7341 | return p.getSignalStrength(); |
| 7342 | } finally { |
| 7343 | Binder.restoreCallingIdentity(identity); |
| 7344 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7345 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7346 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7347 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7348 | * Get the current modem radio state for the given slot. |
| 7349 | * @param slotIndex slot index. |
| 7350 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7351 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7352 | * @return the current radio power state from the modem |
| 7353 | */ |
| 7354 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7355 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7356 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7357 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7358 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7359 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7360 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7361 | } |
| 7362 | |
| 7363 | final long identity = Binder.clearCallingIdentity(); |
| 7364 | try { |
| 7365 | return phone.getRadioPowerState(); |
| 7366 | } finally { |
| 7367 | Binder.restoreCallingIdentity(identity); |
| 7368 | } |
| 7369 | } |
| 7370 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7371 | } |
| 7372 | |
| 7373 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7374 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7375 | * |
| 7376 | * <p>Requires one of the following permissions: |
| 7377 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7378 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7379 | * privileges. |
| 7380 | * |
| 7381 | * @param subId subscription id |
| 7382 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7383 | * {@code false}. |
| 7384 | */ |
| 7385 | @Override |
| 7386 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7387 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7388 | null /* message */); |
| 7389 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7390 | boolean isEnabled = false; |
| 7391 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7392 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7393 | Phone phone = getPhone(subId); |
| 7394 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7395 | } catch (Exception e) { |
| 7396 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7397 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7398 | } finally { |
| 7399 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7400 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7401 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7402 | } |
| 7403 | |
| 7404 | |
| 7405 | /** |
| 7406 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7407 | * |
| 7408 | * <p> Requires permission: |
| 7409 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7410 | * privileges. |
| 7411 | * |
| 7412 | * @param subId subscription id |
| 7413 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7414 | */ |
| 7415 | @Override |
| 7416 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7417 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7418 | mApp, subId, "setDataRoamingEnabled"); |
| 7419 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7420 | final long identity = Binder.clearCallingIdentity(); |
| 7421 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7422 | Phone phone = getPhone(subId); |
| 7423 | if (phone != null) { |
| 7424 | phone.setDataRoamingEnabled(isEnabled); |
| 7425 | } |
| 7426 | } finally { |
| 7427 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7428 | } |
| 7429 | } |
| 7430 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7431 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7432 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7433 | TelephonyPermissions |
| 7434 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7435 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7436 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7437 | boolean isAllowed = true; |
| 7438 | final long identity = Binder.clearCallingIdentity(); |
| 7439 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7440 | Phone phone = getPhone(subId); |
| 7441 | if (phone != null) { |
| 7442 | isAllowed = phone.isCspPlmnEnabled(); |
| 7443 | } |
| 7444 | } finally { |
| 7445 | Binder.restoreCallingIdentity(identity); |
| 7446 | } |
| 7447 | return isAllowed; |
| 7448 | } |
| 7449 | |
| 7450 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7451 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 102b277 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 7452 | try { |
| 7453 | PackageManager pm = mApp.getPackageManager(); |
| 7454 | if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) { |
| 7455 | throw new SecurityException("Calling package " + callingPackage + " does not match " |
| 7456 | + "calling UID"); |
| 7457 | } |
| 7458 | } catch (PackageManager.NameNotFoundException e) { |
| 7459 | throw new SecurityException("Invalid calling package. e=" + e); |
| 7460 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7461 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7462 | try { |
| 7463 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7464 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7465 | } catch (SecurityException e) { |
| 7466 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7467 | // has carrier privileges on an active UICC |
| 7468 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7469 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7470 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7471 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7472 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7473 | |
| 7474 | final long identity = Binder.clearCallingIdentity(); |
| 7475 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7476 | UiccController uiccController = UiccController.getInstance(); |
| 7477 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7478 | if (hasReadPermission) { |
| 7479 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7480 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7481 | |
| 7482 | // Remove private info if the caller doesn't have access |
| 7483 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7484 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7485 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7486 | // is available |
| 7487 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7488 | if (card == null || card.getUiccProfile() == null) { |
| 7489 | // assume no access if the card or profile is unavailable |
| 7490 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7491 | continue; |
| 7492 | } |
| 7493 | UiccProfile profile = card.getUiccProfile(); |
| 7494 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7495 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7496 | filteredInfos.add(cardInfo); |
| 7497 | } else { |
| 7498 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7499 | } |
| 7500 | } |
| 7501 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7502 | } finally { |
| 7503 | Binder.restoreCallingIdentity(identity); |
| 7504 | } |
| 7505 | } |
| 7506 | |
| 7507 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7508 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7509 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7510 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7511 | final long identity = Binder.clearCallingIdentity(); |
| 7512 | try { |
| 7513 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7514 | if (slots == null) { |
| 7515 | Rlog.i(LOG_TAG, "slots is null."); |
| 7516 | return null; |
| 7517 | } |
| 7518 | |
| 7519 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7520 | for (int i = 0; i < slots.length; i++) { |
| 7521 | UiccSlot slot = slots[i]; |
| 7522 | if (slot == null) { |
| 7523 | continue; |
| 7524 | } |
| 7525 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7526 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | UiccCard card = slot.getUiccCard(); |
| 7528 | if (card != null) { |
| 7529 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7530 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7531 | cardId = slot.getEid(); |
| 7532 | if (TextUtils.isEmpty(cardId)) { |
| 7533 | cardId = slot.getIccId(); |
| 7534 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7535 | } |
| 7536 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7537 | if (cardId != null) { |
| 7538 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7539 | // if cardId is an EID, it's all digits so this is fine |
| 7540 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7541 | } |
| 7542 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | int cardState = 0; |
| 7544 | switch (slot.getCardState()) { |
| 7545 | case CARDSTATE_ABSENT: |
| 7546 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7547 | break; |
| 7548 | case CARDSTATE_PRESENT: |
| 7549 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7550 | break; |
| 7551 | case CARDSTATE_ERROR: |
| 7552 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7553 | break; |
| 7554 | case CARDSTATE_RESTRICTED: |
| 7555 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7556 | break; |
| 7557 | default: |
| 7558 | break; |
| 7559 | |
| 7560 | } |
| 7561 | |
| 7562 | infos[i] = new UiccSlotInfo( |
| 7563 | slot.isActive(), |
| 7564 | slot.isEuicc(), |
| 7565 | cardId, |
| 7566 | cardState, |
| 7567 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7568 | slot.isExtendedApduSupported(), |
| 7569 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7570 | } |
| 7571 | return infos; |
| 7572 | } finally { |
| 7573 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7574 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7575 | } |
| 7576 | |
| 7577 | @Override |
| 7578 | public boolean switchSlots(int[] physicalSlots) { |
| 7579 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7580 | |
| 7581 | final long identity = Binder.clearCallingIdentity(); |
| 7582 | try { |
| 7583 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7584 | } finally { |
| 7585 | Binder.restoreCallingIdentity(identity); |
| 7586 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7587 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7588 | |
| 7589 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7590 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7591 | final long identity = Binder.clearCallingIdentity(); |
| 7592 | try { |
| 7593 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7594 | } finally { |
| 7595 | Binder.restoreCallingIdentity(identity); |
| 7596 | } |
| 7597 | } |
| 7598 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7599 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7600 | * A test API to reload the UICC profile. |
| 7601 | * |
| 7602 | * <p>Requires that the calling app has permission |
| 7603 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7604 | * @hide |
| 7605 | */ |
| 7606 | @Override |
| 7607 | public void refreshUiccProfile(int subId) { |
| 7608 | enforceModifyPermission(); |
| 7609 | |
| 7610 | final long identity = Binder.clearCallingIdentity(); |
| 7611 | try { |
| 7612 | Phone phone = getPhone(subId); |
| 7613 | if (phone == null) { |
| 7614 | return; |
| 7615 | } |
| 7616 | UiccCard uiccCard = phone.getUiccCard(); |
| 7617 | if (uiccCard == null) { |
| 7618 | return; |
| 7619 | } |
| 7620 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7621 | if (uiccProfile == null) { |
| 7622 | return; |
| 7623 | } |
| 7624 | uiccProfile.refresh(); |
| 7625 | } finally { |
| 7626 | Binder.restoreCallingIdentity(identity); |
| 7627 | } |
| 7628 | } |
| 7629 | |
| 7630 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7631 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7632 | */ |
| 7633 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7634 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7635 | } |
| 7636 | |
| 7637 | /** |
| 7638 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7639 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7640 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7641 | */ |
| 7642 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7643 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7644 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7645 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7646 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7647 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7648 | return isDataRoamingEnabled; |
| 7649 | } |
| 7650 | |
| 7651 | /** |
| 7652 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7653 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7654 | */ |
| 7655 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7656 | List<Integer> list = TelephonyProperties.default_network(); |
| 7657 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7658 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7659 | return list.get(phoneId); |
| 7660 | } |
| 7661 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7662 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7663 | |
| 7664 | @Override |
| 7665 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7666 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7667 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7668 | |
| 7669 | final long identity = Binder.clearCallingIdentity(); |
| 7670 | try { |
| 7671 | final Phone phone = getPhone(subId); |
| 7672 | if (phone == null) { |
| 7673 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7674 | return; |
| 7675 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7676 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7677 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7678 | } finally { |
| 7679 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7680 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7681 | } |
| 7682 | |
| 7683 | @Override |
| 7684 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7685 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7686 | |
| 7687 | final long identity = Binder.clearCallingIdentity(); |
| 7688 | try { |
| 7689 | final Phone phone = getPhone(subId); |
| 7690 | if (phone == null) { |
| 7691 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7692 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7693 | } |
| 7694 | return phone.getCarrierIdListVersion(); |
| 7695 | } finally { |
| 7696 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7697 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7698 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7699 | |
| 7700 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7701 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7702 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7703 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7704 | mApp, subId, callingPackage, callingFeatureId, |
| 7705 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7706 | return -1; |
| 7707 | } |
| 7708 | |
| 7709 | final long identity = Binder.clearCallingIdentity(); |
| 7710 | try { |
| 7711 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7712 | } finally { |
| 7713 | Binder.restoreCallingIdentity(identity); |
| 7714 | } |
| 7715 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7716 | |
| 7717 | @Override |
| 7718 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7719 | TelephonyPermissions |
| 7720 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7721 | mApp, subId, "getCdmaRoamingMode"); |
| 7722 | |
| 7723 | final long identity = Binder.clearCallingIdentity(); |
| 7724 | try { |
| 7725 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7726 | } finally { |
| 7727 | Binder.restoreCallingIdentity(identity); |
| 7728 | } |
| 7729 | } |
| 7730 | |
| 7731 | @Override |
| 7732 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7734 | mApp, subId, "setCdmaRoamingMode"); |
| 7735 | |
| 7736 | final long identity = Binder.clearCallingIdentity(); |
| 7737 | try { |
| 7738 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7739 | } finally { |
| 7740 | Binder.restoreCallingIdentity(identity); |
| 7741 | } |
| 7742 | } |
| 7743 | |
| 7744 | @Override |
| 7745 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7747 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7748 | |
| 7749 | final long identity = Binder.clearCallingIdentity(); |
| 7750 | try { |
| 7751 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7752 | } finally { |
| 7753 | Binder.restoreCallingIdentity(identity); |
| 7754 | } |
| 7755 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7756 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7757 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7758 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7759 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7760 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7761 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7762 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7763 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7764 | } |
| 7765 | final long identity = Binder.clearCallingIdentity(); |
| 7766 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7767 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7768 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7769 | if (phone.getEmergencyNumberTracker() != null |
| 7770 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7771 | emergencyNumberListInternal.put( |
| 7772 | phone.getSubId(), |
| 7773 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7774 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7775 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7776 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7777 | } finally { |
| 7778 | Binder.restoreCallingIdentity(identity); |
| 7779 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7780 | } |
| 7781 | |
| 7782 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7783 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7784 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7785 | if (!exactMatch) { |
| 7786 | TelephonyPermissions |
| 7787 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7788 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7789 | } |
| 7790 | final long identity = Binder.clearCallingIdentity(); |
| 7791 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7792 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7793 | if (phone.getEmergencyNumberTracker() != null |
| 7794 | && phone.getEmergencyNumberTracker() != null) { |
| 7795 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7796 | number, exactMatch)) { |
| 7797 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7798 | } |
| 7799 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7800 | } |
| 7801 | return false; |
| 7802 | } finally { |
| 7803 | Binder.restoreCallingIdentity(identity); |
| 7804 | } |
| 7805 | } |
| 7806 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7807 | /** |
| 7808 | * Update emergency number list for test mode. |
| 7809 | */ |
| 7810 | @Override |
| 7811 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7812 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7813 | "updateEmergencyNumberListTestMode"); |
| 7814 | |
| 7815 | final long identity = Binder.clearCallingIdentity(); |
| 7816 | try { |
| 7817 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7818 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7819 | if (tracker != null) { |
| 7820 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7821 | } |
| 7822 | } |
| 7823 | } finally { |
| 7824 | Binder.restoreCallingIdentity(identity); |
| 7825 | } |
| 7826 | } |
| 7827 | |
| 7828 | /** |
| 7829 | * Get the full emergency number list for test mode. |
| 7830 | */ |
| 7831 | @Override |
| 7832 | public List<String> getEmergencyNumberListTestMode() { |
| 7833 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7834 | "getEmergencyNumberListTestMode"); |
| 7835 | |
| 7836 | final long identity = Binder.clearCallingIdentity(); |
| 7837 | try { |
| 7838 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7839 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7840 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7841 | if (tracker != null) { |
| 7842 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7843 | emergencyNumbers.add(num.getNumber()); |
| 7844 | } |
| 7845 | } |
| 7846 | } |
| 7847 | return new ArrayList<>(emergencyNumbers); |
| 7848 | } finally { |
| 7849 | Binder.restoreCallingIdentity(identity); |
| 7850 | } |
| 7851 | } |
| 7852 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7853 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7854 | public int getEmergencyNumberDbVersion(int subId) { |
| 7855 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7856 | |
| 7857 | final long identity = Binder.clearCallingIdentity(); |
| 7858 | try { |
| 7859 | final Phone phone = getPhone(subId); |
| 7860 | if (phone == null) { |
| 7861 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7862 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7863 | } |
| 7864 | return phone.getEmergencyNumberDbVersion(); |
| 7865 | } finally { |
| 7866 | Binder.restoreCallingIdentity(identity); |
| 7867 | } |
| 7868 | } |
| 7869 | |
| 7870 | @Override |
| 7871 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7872 | enforceModifyPermission(); |
| 7873 | |
| 7874 | final long identity = Binder.clearCallingIdentity(); |
| 7875 | try { |
| 7876 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7877 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7878 | if (tracker != null) { |
| 7879 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7880 | } |
| 7881 | } |
| 7882 | } finally { |
| 7883 | Binder.restoreCallingIdentity(identity); |
| 7884 | } |
| 7885 | } |
| 7886 | |
| 7887 | @Override |
| 7888 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7889 | enforceActiveEmergencySessionPermission(); |
| 7890 | |
| 7891 | final long identity = Binder.clearCallingIdentity(); |
| 7892 | try { |
| 7893 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7894 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7895 | if (tracker != null) { |
| 7896 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7897 | } |
| 7898 | } |
| 7899 | } finally { |
| 7900 | Binder.restoreCallingIdentity(identity); |
| 7901 | } |
| 7902 | } |
| 7903 | |
| 7904 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7905 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7906 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7907 | Phone phone = getPhone(subId); |
| 7908 | if (phone == null) { |
| 7909 | return null; |
| 7910 | } |
| 7911 | final long identity = Binder.clearCallingIdentity(); |
| 7912 | try { |
| 7913 | UiccProfile profile = UiccController.getInstance() |
| 7914 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7915 | if (profile != null) { |
| 7916 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7917 | } |
| 7918 | } finally { |
| 7919 | Binder.restoreCallingIdentity(identity); |
| 7920 | } |
| 7921 | return null; |
| 7922 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7923 | |
| 7924 | /** |
| 7925 | * Enable or disable a modem stack. |
| 7926 | */ |
| 7927 | @Override |
| 7928 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7929 | enforceModifyPermission(); |
| 7930 | |
| 7931 | final long identity = Binder.clearCallingIdentity(); |
| 7932 | try { |
| 7933 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7934 | if (phone == null) { |
| 7935 | return false; |
| 7936 | } else { |
| 7937 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7938 | } |
| 7939 | } finally { |
| 7940 | Binder.restoreCallingIdentity(identity); |
| 7941 | } |
| 7942 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7943 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7944 | /** |
| 7945 | * Whether a modem stack is enabled or not. |
| 7946 | */ |
| 7947 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7948 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7949 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7950 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7951 | if (phone == null) return false; |
| 7952 | |
| 7953 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7954 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7955 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7956 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7957 | } |
| 7958 | |
| 7959 | final long identity = Binder.clearCallingIdentity(); |
| 7960 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7961 | try { |
| 7962 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7963 | } catch (NoSuchElementException ex) { |
| 7964 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7965 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7966 | } finally { |
| 7967 | Binder.restoreCallingIdentity(identity); |
| 7968 | } |
| 7969 | } |
| 7970 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7971 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7972 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7973 | enforceModifyPermission(); |
| 7974 | |
| 7975 | final long identity = Binder.clearCallingIdentity(); |
| 7976 | try { |
| 7977 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7978 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7979 | .commit(); |
| 7980 | } finally { |
| 7981 | Binder.restoreCallingIdentity(identity); |
| 7982 | } |
| 7983 | } |
| 7984 | |
| 7985 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7986 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7987 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7988 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7989 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7990 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7991 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7992 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7993 | |
| 7994 | final long identity = Binder.clearCallingIdentity(); |
| 7995 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7996 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7997 | } finally { |
| 7998 | Binder.restoreCallingIdentity(identity); |
| 7999 | } |
| 8000 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8001 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8002 | @TelephonyManager.IsMultiSimSupportedResult |
| 8003 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8004 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8005 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8006 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8007 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8008 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8009 | } |
| 8010 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8011 | // supported by the modem, indicate that it is restricted. |
| 8012 | PhoneCapability staticCapability = |
| 8013 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8014 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8015 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8016 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8017 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8018 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8019 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8020 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8021 | } |
| 8022 | // Check if support of multiple SIMs is restricted by carrier |
| 8023 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8024 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8025 | } |
| 8026 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8027 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8028 | } |
| 8029 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8030 | /** |
| 8031 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8032 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8033 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8034 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8035 | * @param numOfSims number of active sims we want to switch to |
| 8036 | */ |
| 8037 | @Override |
| 8038 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8039 | if (numOfSims == 1) { |
| 8040 | enforceModifyPermission(); |
| 8041 | } else { |
| 8042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8043 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8044 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8045 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8046 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8047 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8048 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8049 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8050 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8051 | return; |
| 8052 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8053 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8054 | } finally { |
| 8055 | Binder.restoreCallingIdentity(identity); |
| 8056 | } |
| 8057 | } |
| 8058 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8059 | @Override |
| 8060 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8061 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8062 | Phone phone = getPhone(subId); |
| 8063 | if (phone == null) { |
| 8064 | return false; |
| 8065 | } |
| 8066 | final long identity = Binder.clearCallingIdentity(); |
| 8067 | try { |
| 8068 | UiccCard uiccCard = phone.getUiccCard(); |
| 8069 | if (uiccCard == null) { |
| 8070 | return false; |
| 8071 | } |
| 8072 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8073 | if (uiccProfile == null) { |
| 8074 | return false; |
| 8075 | } |
| 8076 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8077 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8078 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8079 | } |
| 8080 | return false; |
| 8081 | } finally { |
| 8082 | Binder.restoreCallingIdentity(identity); |
| 8083 | } |
| 8084 | } |
| 8085 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8086 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8087 | * Get whether making changes to modem configurations will trigger reboot. |
| 8088 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8089 | */ |
| 8090 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8091 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8092 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8093 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8094 | mApp, subId, callingPackage, callingFeatureId, |
| 8095 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8096 | return false; |
| 8097 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8098 | final long identity = Binder.clearCallingIdentity(); |
| 8099 | try { |
| 8100 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8101 | } finally { |
| 8102 | Binder.restoreCallingIdentity(identity); |
| 8103 | } |
| 8104 | } |
| 8105 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8106 | private void updateModemStateMetrics() { |
| 8107 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8108 | // TODO: check the state for each modem if the api is ready. |
| 8109 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8110 | } |
| 8111 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8112 | @Override |
| 8113 | public int[] getSlotsMapping() { |
| 8114 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8115 | |
| 8116 | final long identity = Binder.clearCallingIdentity(); |
| 8117 | try { |
| 8118 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8119 | // All logical slots should have a mapping to a physical slot. |
| 8120 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8121 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8122 | for (int i = 0; i < slotInfos.length; i++) { |
| 8123 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8124 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8125 | } |
| 8126 | } |
| 8127 | return logicalSlotsMapping; |
| 8128 | } finally { |
| 8129 | Binder.restoreCallingIdentity(identity); |
| 8130 | } |
| 8131 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8132 | |
| 8133 | /** |
| 8134 | * Get the IRadio HAL Version |
| 8135 | */ |
| 8136 | @Override |
| 8137 | public int getRadioHalVersion() { |
| 8138 | Phone phone = getDefaultPhone(); |
| 8139 | if (phone == null) return -1; |
| 8140 | HalVersion hv = phone.getHalVersion(); |
| 8141 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8142 | return hv.major * 100 + hv.minor; |
| 8143 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8144 | |
| 8145 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8146 | * Get the current calling package name. |
| 8147 | * @return the current calling package name |
| 8148 | */ |
| 8149 | @Override |
| 8150 | public String getCurrentPackageName() { |
| 8151 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8152 | } |
| 8153 | |
| 8154 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8155 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8156 | * corresponding network requests on a subId. |
| 8157 | * |
| 8158 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8159 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8160 | * 2) APN is un-metered for this subscription, or |
| 8161 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8162 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8163 | * |
| 8164 | * @return whether data is allowed for a apn type. |
| 8165 | * |
| 8166 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8167 | */ |
| 8168 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8169 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8170 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8171 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8172 | |
| 8173 | // Now that all security checks passes, perform the operation as ourselves. |
| 8174 | final long identity = Binder.clearCallingIdentity(); |
| 8175 | try { |
| 8176 | Phone phone = getPhone(subId); |
| 8177 | if (phone == null) return false; |
| 8178 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8179 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8180 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8181 | } finally { |
| 8182 | Binder.restoreCallingIdentity(identity); |
| 8183 | } |
| 8184 | } |
| 8185 | |
| 8186 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8187 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8188 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8189 | |
| 8190 | // Now that all security checks passes, perform the operation as ourselves. |
| 8191 | final long identity = Binder.clearCallingIdentity(); |
| 8192 | try { |
| 8193 | Phone phone = getPhone(subId); |
| 8194 | if (phone == null) return true; // By default return true. |
| 8195 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8196 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8197 | } finally { |
| 8198 | Binder.restoreCallingIdentity(identity); |
| 8199 | } |
| 8200 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8201 | |
| 8202 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8203 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8204 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8205 | enforceModifyPermission(); |
| 8206 | long token = Binder.clearCallingIdentity(); |
| 8207 | try { |
| 8208 | Phone phone = getPhone(subscriptionId); |
| 8209 | if (phone == null) { |
| 8210 | try { |
| 8211 | if (resultCallback != null) { |
| 8212 | resultCallback.accept(false); |
| 8213 | } |
| 8214 | } catch (RemoteException e) { |
| 8215 | // ignore |
| 8216 | } |
| 8217 | return; |
| 8218 | } |
| 8219 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8220 | Pair.create(specifiers, (x) -> { |
| 8221 | try { |
| 8222 | if (resultCallback != null) { |
| 8223 | resultCallback.accept(x); |
| 8224 | } |
| 8225 | } catch (RemoteException e) { |
| 8226 | // ignore |
| 8227 | } |
| 8228 | }); |
| 8229 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8230 | } finally { |
| 8231 | Binder.restoreCallingIdentity(token); |
| 8232 | } |
| 8233 | } |
| 8234 | |
| 8235 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8236 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8237 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8238 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8239 | if (iccRecords == null) { |
| 8240 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8241 | return false; |
| 8242 | } |
| 8243 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8244 | } |
| 8245 | |
| 8246 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8247 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8248 | if (callingPackage == null) { |
| 8249 | callingPackage = getCurrentPackageName(); |
| 8250 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8251 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8252 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8253 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8254 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8255 | } |
| 8256 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8257 | Intent intent = new Intent(); |
| 8258 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8259 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8260 | // Bring up choose default SMS subscription dialog right now |
| 8261 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8262 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8263 | mApp.startActivity(intent); |
| 8264 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8265 | |
| 8266 | @Override |
| 8267 | public String getMmsUAProfUrl(int subId) { |
| 8268 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8269 | final long identity = Binder.clearCallingIdentity(); |
| 8270 | try { |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8271 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8272 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8273 | } finally { |
| 8274 | Binder.restoreCallingIdentity(identity); |
| 8275 | } |
| 8276 | } |
| 8277 | |
| 8278 | @Override |
| 8279 | public String getMmsUserAgent(int subId) { |
| 8280 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8281 | final long identity = Binder.clearCallingIdentity(); |
| 8282 | try { |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8283 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8284 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8285 | } finally { |
| 8286 | Binder.restoreCallingIdentity(identity); |
| 8287 | } |
| 8288 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8289 | |
| 8290 | @Override |
| 8291 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8292 | enforceModifyPermission(); |
| 8293 | |
| 8294 | // Now that all security checks passes, perform the operation as ourselves. |
| 8295 | final long identity = Binder.clearCallingIdentity(); |
| 8296 | try { |
| 8297 | Phone phone = getPhone(subId); |
| 8298 | if (phone == null) return false; |
| 8299 | |
| 8300 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8301 | } finally { |
| 8302 | Binder.restoreCallingIdentity(identity); |
| 8303 | } |
| 8304 | } |
| 8305 | |
| 8306 | @Override |
| 8307 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8308 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8309 | |
| 8310 | // Now that all security checks passes, perform the operation as ourselves. |
| 8311 | final long identity = Binder.clearCallingIdentity(); |
| 8312 | try { |
| 8313 | Phone phone = getPhone(subId); |
| 8314 | if (phone == null) return false; |
| 8315 | |
| 8316 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8317 | } finally { |
| 8318 | Binder.restoreCallingIdentity(identity); |
| 8319 | } |
| 8320 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8321 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8322 | @Override |
| 8323 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8324 | enforceModifyPermission(); |
| 8325 | |
| 8326 | // Now that all security checks passes, perform the operation as ourselves. |
| 8327 | final long identity = Binder.clearCallingIdentity(); |
| 8328 | try { |
| 8329 | Phone phone = getPhone(subId); |
| 8330 | if (phone == null) return false; |
| 8331 | |
| 8332 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8333 | } finally { |
| 8334 | Binder.restoreCallingIdentity(identity); |
| 8335 | } |
| 8336 | } |
| 8337 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8338 | /** |
| 8339 | * Updates whether conference event pacakge handling is enabled. |
| 8340 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8341 | * otherwise. |
| 8342 | */ |
| 8343 | @Override |
| 8344 | public void setCepEnabled(boolean isCepEnabled) { |
| 8345 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8346 | |
| 8347 | final long identity = Binder.clearCallingIdentity(); |
| 8348 | try { |
| 8349 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8350 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8351 | Phone defaultPhone = phone.getImsPhone(); |
| 8352 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8353 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8354 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8355 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8356 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8357 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8358 | + imsPhone.getMsisdn()); |
| 8359 | } |
| 8360 | } |
| 8361 | } finally { |
| 8362 | Binder.restoreCallingIdentity(identity); |
| 8363 | } |
| 8364 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8365 | |
| 8366 | /** |
| 8367 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8368 | * |
| 8369 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8370 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8371 | * before being read. |
| 8372 | */ |
| 8373 | @Override |
| 8374 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8375 | isCompressed) { |
| 8376 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8377 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8378 | try { |
| 8379 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8380 | if (configBinder == null) { |
| 8381 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8382 | } else { |
| 8383 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8384 | } |
| 8385 | } catch (RemoteException e) { |
| 8386 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8387 | } |
| 8388 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8389 | |
| 8390 | @Override |
| 8391 | public boolean isIccLockEnabled(int subId) { |
| 8392 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8393 | |
| 8394 | // Now that all security checks passes, perform the operation as ourselves. |
| 8395 | final long identity = Binder.clearCallingIdentity(); |
| 8396 | try { |
| 8397 | Phone phone = getPhone(subId); |
| 8398 | if (phone != null && phone.getIccCard() != null) { |
| 8399 | return phone.getIccCard().getIccLockEnabled(); |
| 8400 | } else { |
| 8401 | return false; |
| 8402 | } |
| 8403 | } finally { |
| 8404 | Binder.restoreCallingIdentity(identity); |
| 8405 | } |
| 8406 | } |
| 8407 | |
| 8408 | /** |
| 8409 | * Set the ICC pin lock enabled or disabled. |
| 8410 | * |
| 8411 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8412 | * three cases: |
| 8413 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8414 | * successfully. |
| 8415 | * - Positive number and zero for remaining password attempts. |
| 8416 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8417 | * |
| 8418 | */ |
| 8419 | @Override |
| 8420 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8421 | enforceModifyPermission(); |
| 8422 | |
| 8423 | Phone phone = getPhone(subId); |
| 8424 | if (phone == null) { |
| 8425 | return 0; |
| 8426 | } |
| 8427 | // Now that all security checks passes, perform the operation as ourselves. |
| 8428 | final long identity = Binder.clearCallingIdentity(); |
| 8429 | try { |
| 8430 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8431 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8432 | return attemptsRemaining; |
| 8433 | |
| 8434 | } catch (Exception e) { |
| 8435 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8436 | } finally { |
| 8437 | Binder.restoreCallingIdentity(identity); |
| 8438 | } |
| 8439 | return 0; |
| 8440 | } |
| 8441 | |
| 8442 | /** |
| 8443 | * Change the ICC password used in ICC pin lock. |
| 8444 | * |
| 8445 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8446 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8447 | * - Positive number and zero for remaining password attempts. |
| 8448 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8449 | * |
| 8450 | */ |
| 8451 | @Override |
| 8452 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8453 | enforceModifyPermission(); |
| 8454 | |
| 8455 | Phone phone = getPhone(subId); |
| 8456 | if (phone == null) { |
| 8457 | return 0; |
| 8458 | } |
| 8459 | // Now that all security checks passes, perform the operation as ourselves. |
| 8460 | final long identity = Binder.clearCallingIdentity(); |
| 8461 | try { |
| 8462 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8463 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8464 | return attemptsRemaining; |
| 8465 | |
| 8466 | } catch (Exception e) { |
| 8467 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8468 | } finally { |
| 8469 | Binder.restoreCallingIdentity(identity); |
| 8470 | } |
| 8471 | return 0; |
| 8472 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8473 | |
| 8474 | /** |
| 8475 | * Request for receiving user activity notification |
| 8476 | */ |
| 8477 | @Override |
| 8478 | public void requestUserActivityNotification() { |
| 8479 | if (!mNotifyUserActivity.get() |
| 8480 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8481 | mNotifyUserActivity.set(true); |
| 8482 | } |
| 8483 | } |
| 8484 | |
| 8485 | /** |
| 8486 | * Called when userActivity is signalled in the power manager. |
| 8487 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8488 | */ |
| 8489 | @Override |
| 8490 | public void userActivity() { |
| 8491 | // *************************************** |
| 8492 | // * Inherited from PhoneWindowManager * |
| 8493 | // *************************************** |
| 8494 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8495 | // WITH ITS LOCKS HELD. |
| 8496 | // |
| 8497 | // This code must be VERY careful about the locks |
| 8498 | // it acquires. |
| 8499 | // In fact, the current code acquires way too many, |
| 8500 | // and probably has lurking deadlocks. |
| 8501 | |
| 8502 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8503 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8504 | } |
| 8505 | |
| 8506 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8507 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8508 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8509 | } |
| 8510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8511 | } |