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; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 26 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 29 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 32 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 37 | import android.net.NetworkStats; |
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; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 50 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 51 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 54 | import android.os.ShellCallback; |
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 | 8ff344d | 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 | 8d298d4 | 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 | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 67 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 68 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 69 | import android.telephony.CellIdentity; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 71 | import android.telephony.CellInfoGsm; |
| 72 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 73 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 74 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 75 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 76 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 77 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 78 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 79 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 80 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 81 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 82 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 83 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 84 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 85 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 86 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 87 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 88 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 90 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 91 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 92 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 93 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 94 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 95 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 96 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 97 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 98 | import android.telephony.data.ApnSetting; |
| 99 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 100 | import android.telephony.gsm.GsmCellLocation; |
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 | 774ba36 | 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 | 77b832e | 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; |
| 113 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 118 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 119 | import android.util.Slog; |
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; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 156 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.IccIoResult; |
| 160 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 167 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 169 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 170 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 171 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 172 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 173 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 175 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 176 | import java.io.FileDescriptor; |
| 177 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 178 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 179 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 180 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 181 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 182 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 183 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 184 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 185 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 186 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * Implementation of the ITelephony interface. |
| 190 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 191 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 193 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 194 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 195 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | |
| 197 | // Message codes used with mMainThreadHandler |
| 198 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 199 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 200 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 201 | private static final int CMD_OPEN_CHANNEL = 9; |
| 202 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 203 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 204 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 205 | private static final int CMD_NV_READ_ITEM = 13; |
| 206 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 207 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 208 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 209 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 210 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 211 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 212 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 213 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 214 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 215 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 216 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 217 | private static final int CMD_SEND_ENVELOPE = 25; |
| 218 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 219 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 220 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 221 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 222 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 223 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 224 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 225 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 226 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 227 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 228 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 229 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 230 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 231 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 232 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 233 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 234 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 235 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 236 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 237 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 238 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 239 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 240 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 241 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 242 | private static final int CMD_SWITCH_SLOTS = 50; |
| 243 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 244 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 245 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 246 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 247 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 248 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 249 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 250 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 251 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 253 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 254 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 255 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 256 | private static final int CMD_MODEM_REBOOT = 64; |
| 257 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 258 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 259 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 260 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 261 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 262 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 263 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 264 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 265 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 266 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 267 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 268 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 269 | // Parameters of select command. |
| 270 | private static final int SELECT_COMMAND = 0xA4; |
| 271 | private static final int SELECT_P1 = 0x04; |
| 272 | private static final int SELECT_P2 = 0; |
| 273 | private static final int SELECT_P3 = 0x10; |
| 274 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | /** The singleton instance. */ |
| 276 | private static PhoneInterfaceManager sInstance; |
| 277 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 278 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 279 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 280 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 281 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 282 | private AppOpsManager mAppOps; |
| 283 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 284 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 285 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 286 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 287 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 288 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 289 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 290 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 291 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 292 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 293 | // String to store multi SIM allowed |
| 294 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 295 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 296 | // The AID of ISD-R. |
| 297 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 298 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 299 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 300 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 301 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 302 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 303 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 304 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 305 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 306 | */ |
| 307 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 308 | "reset_network_erase_modem_config_enabled"; |
| 309 | |
| 310 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 311 | * A request object to use for transmitting data to an ICC. |
| 312 | */ |
| 313 | private static final class IccAPDUArgument { |
| 314 | public int channel, cla, command, p1, p2, p3; |
| 315 | public String data; |
| 316 | |
| 317 | public IccAPDUArgument(int channel, int cla, int command, |
| 318 | int p1, int p2, int p3, String data) { |
| 319 | this.channel = channel; |
| 320 | this.cla = cla; |
| 321 | this.command = command; |
| 322 | this.p1 = p1; |
| 323 | this.p2 = p2; |
| 324 | this.p3 = p3; |
| 325 | this.data = data; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 330 | * A request object to use for transmitting data to an ICC. |
| 331 | */ |
| 332 | private static final class ManualNetworkSelectionArgument { |
| 333 | public OperatorInfo operatorInfo; |
| 334 | public boolean persistSelection; |
| 335 | |
| 336 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 337 | this.operatorInfo = operatorInfo; |
| 338 | this.persistSelection = persistSelection; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 344 | * request after sending. The main thread will notify the request when it is complete. |
| 345 | */ |
| 346 | private static final class MainThreadRequest { |
| 347 | /** The argument to use for the request */ |
| 348 | public Object argument; |
| 349 | /** The result of the request that is run on the main thread */ |
| 350 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 351 | // The subscriber id that this request applies to. Defaults to |
| 352 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 353 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 354 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 355 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 356 | public Phone phone; |
| 357 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 358 | public WorkSource workSource; |
| 359 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 360 | public MainThreadRequest(Object argument) { |
| 361 | this.argument = argument; |
| 362 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 363 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 364 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 365 | this.argument = argument; |
| 366 | if (phone != null) { |
| 367 | this.phone = phone; |
| 368 | } |
| 369 | this.workSource = workSource; |
| 370 | } |
| 371 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 372 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 373 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 374 | if (subId != null) { |
| 375 | this.subId = subId; |
| 376 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 377 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 378 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 381 | private static final class IncomingThirdPartyCallArgs { |
| 382 | public final ComponentName component; |
| 383 | public final String callId; |
| 384 | public final String callerDisplayName; |
| 385 | |
| 386 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 387 | String callerDisplayName) { |
| 388 | this.component = component; |
| 389 | this.callId = callId; |
| 390 | this.callerDisplayName = callerDisplayName; |
| 391 | } |
| 392 | } |
| 393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 394 | /** |
| 395 | * A handler that processes messages on the main thread in the phone process. Since many |
| 396 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 397 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 398 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 399 | * on, which will be notified when the operation completes and will contain the result of the |
| 400 | * request. |
| 401 | * |
| 402 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 403 | * note that request.result must be set to something non-null for the calling thread to |
| 404 | * unblock. |
| 405 | */ |
| 406 | private final class MainThreadHandler extends Handler { |
| 407 | @Override |
| 408 | public void handleMessage(Message msg) { |
| 409 | MainThreadRequest request; |
| 410 | Message onCompleted; |
| 411 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 412 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 413 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 414 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | |
| 416 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 417 | case CMD_HANDLE_USSD_REQUEST: { |
| 418 | request = (MainThreadRequest) msg.obj; |
| 419 | final Phone phone = getPhoneFromRequest(request); |
| 420 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 421 | String ussdRequest = ussdObject.first; |
| 422 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 423 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 424 | if (!isUssdApiAllowed(request.subId)) { |
| 425 | // Carrier does not support use of this API, return failure. |
| 426 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 427 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 428 | Bundle returnData = new Bundle(); |
| 429 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 430 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 431 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 432 | request.result = true; |
| 433 | notifyRequester(request); |
| 434 | return; |
| 435 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 436 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 437 | try { |
| 438 | request.result = phone != null |
| 439 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 440 | } catch (CallStateException cse) { |
| 441 | request.result = false; |
| 442 | } |
| 443 | // Wake up the requesting thread |
| 444 | notifyRequester(request); |
| 445 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 448 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 450 | final Phone phone = getPhoneFromRequest(request); |
| 451 | request.result = phone != null ? |
| 452 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 453 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 454 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 455 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 456 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 457 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 458 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 459 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 460 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 461 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 462 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 463 | if (uiccCard == null) { |
| 464 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 465 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 466 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 467 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 468 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 469 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 470 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 471 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 472 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 473 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 474 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 475 | break; |
| 476 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 478 | ar = (AsyncResult) msg.obj; |
| 479 | request = (MainThreadRequest) ar.userObj; |
| 480 | if (ar.exception == null && ar.result != null) { |
| 481 | request.result = ar.result; |
| 482 | } else { |
| 483 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 484 | if (ar.result == null) { |
| 485 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 486 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 487 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 488 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 489 | } else { |
| 490 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 491 | } |
| 492 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 493 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 494 | break; |
| 495 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 497 | request = (MainThreadRequest) msg.obj; |
| 498 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 499 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | if (uiccCard == null) { |
| 501 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 502 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 503 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 504 | } else { |
| 505 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 506 | request); |
| 507 | uiccCard.iccTransmitApduBasicChannel( |
| 508 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 509 | iccArgument.p3, iccArgument.data, onCompleted); |
| 510 | } |
| 511 | break; |
| 512 | |
| 513 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 514 | ar = (AsyncResult) msg.obj; |
| 515 | request = (MainThreadRequest) ar.userObj; |
| 516 | if (ar.exception == null && ar.result != null) { |
| 517 | request.result = ar.result; |
| 518 | } else { |
| 519 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 520 | if (ar.result == null) { |
| 521 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 522 | } else if (ar.exception instanceof CommandException) { |
| 523 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 524 | ar.exception); |
| 525 | } else { |
| 526 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 527 | } |
| 528 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 529 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | break; |
| 531 | |
| 532 | case CMD_EXCHANGE_SIM_IO: |
| 533 | request = (MainThreadRequest) msg.obj; |
| 534 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 535 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 536 | if (uiccCard == null) { |
| 537 | loge("iccExchangeSimIO: No UICC"); |
| 538 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 539 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 540 | } else { |
| 541 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 542 | request); |
| 543 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 544 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 545 | iccArgument.data, onCompleted); |
| 546 | } |
| 547 | break; |
| 548 | |
| 549 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 550 | ar = (AsyncResult) msg.obj; |
| 551 | request = (MainThreadRequest) ar.userObj; |
| 552 | if (ar.exception == null && ar.result != null) { |
| 553 | request.result = ar.result; |
| 554 | } else { |
| 555 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 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 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 560 | case CMD_SEND_ENVELOPE: |
| 561 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 562 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 563 | if (uiccCard == null) { |
| 564 | loge("sendEnvelopeWithStatus: No UICC"); |
| 565 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 567 | } else { |
| 568 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 569 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 570 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 571 | break; |
| 572 | |
| 573 | case EVENT_SEND_ENVELOPE_DONE: |
| 574 | ar = (AsyncResult) msg.obj; |
| 575 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 576 | if (ar.exception == null && ar.result != null) { |
| 577 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 578 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 579 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 580 | if (ar.result == null) { |
| 581 | loge("sendEnvelopeWithStatus: Empty response"); |
| 582 | } else if (ar.exception instanceof CommandException) { |
| 583 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 584 | ar.exception); |
| 585 | } else { |
| 586 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 587 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 588 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 589 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 590 | break; |
| 591 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 592 | case CMD_OPEN_CHANNEL: |
| 593 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 594 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 595 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 596 | if (uiccCard == null) { |
| 597 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 598 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 599 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 600 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 601 | } else { |
| 602 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 603 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 604 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 605 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | case EVENT_OPEN_CHANNEL_DONE: |
| 609 | ar = (AsyncResult) msg.obj; |
| 610 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 612 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | int[] result = (int[]) ar.result; |
| 614 | int channelId = result[0]; |
| 615 | byte[] selectResponse = null; |
| 616 | if (result.length > 1) { |
| 617 | selectResponse = new byte[result.length - 1]; |
| 618 | for (int i = 1; i < result.length; ++i) { |
| 619 | selectResponse[i - 1] = (byte) result[i]; |
| 620 | } |
| 621 | } |
| 622 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 623 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 624 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 625 | if (ar.result == null) { |
| 626 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 628 | if (ar.exception != null) { |
| 629 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 630 | } |
| 631 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 632 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 633 | if (ar.exception instanceof CommandException) { |
| 634 | CommandException.Error error = |
| 635 | ((CommandException) (ar.exception)).getCommandError(); |
| 636 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 637 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 638 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 639 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 643 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 645 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 646 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | case CMD_CLOSE_CHANNEL: |
| 650 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 651 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 652 | if (uiccCard == null) { |
| 653 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 654 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 655 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 656 | } else { |
| 657 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 658 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 659 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 664 | break; |
| 665 | |
| 666 | case CMD_NV_READ_ITEM: |
| 667 | request = (MainThreadRequest) msg.obj; |
| 668 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 669 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 670 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 671 | break; |
| 672 | |
| 673 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | ar = (AsyncResult) msg.obj; |
| 675 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 676 | if (ar.exception == null && ar.result != null) { |
| 677 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 679 | request.result = ""; |
| 680 | if (ar.result == null) { |
| 681 | loge("nvReadItem: Empty response"); |
| 682 | } else if (ar.exception instanceof CommandException) { |
| 683 | loge("nvReadItem: CommandException: " + |
| 684 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 685 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 686 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | } |
| 688 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 689 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | break; |
| 691 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | case CMD_NV_WRITE_ITEM: |
| 693 | request = (MainThreadRequest) msg.obj; |
| 694 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 695 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 696 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 697 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_NV_WRITE_ITEM_DONE: |
| 701 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 702 | break; |
| 703 | |
| 704 | case CMD_NV_WRITE_CDMA_PRL: |
| 705 | request = (MainThreadRequest) msg.obj; |
| 706 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 707 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | break; |
| 709 | |
| 710 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 711 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 712 | break; |
| 713 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 714 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 715 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 716 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 717 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | break; |
| 719 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 720 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 721 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 722 | break; |
| 723 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 724 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 725 | request = (MainThreadRequest) msg.obj; |
| 726 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 727 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 731 | ar = (AsyncResult) msg.obj; |
| 732 | request = (MainThreadRequest) ar.userObj; |
| 733 | if (ar.exception == null && ar.result != null) { |
| 734 | request.result = ar.result; // Integer |
| 735 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 736 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 737 | if (ar.result == null) { |
| 738 | loge("getPreferredNetworkType: Empty response"); |
| 739 | } else if (ar.exception instanceof CommandException) { |
| 740 | loge("getPreferredNetworkType: CommandException: " + |
| 741 | ar.exception); |
| 742 | } else { |
| 743 | loge("getPreferredNetworkType: Unknown exception"); |
| 744 | } |
| 745 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 746 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 747 | break; |
| 748 | |
| 749 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 750 | request = (MainThreadRequest) msg.obj; |
| 751 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 752 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 753 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 754 | break; |
| 755 | |
| 756 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 757 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 758 | break; |
| 759 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 760 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 761 | request = (MainThreadRequest)msg.obj; |
| 762 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 763 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 764 | break; |
| 765 | |
| 766 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 767 | ar = (AsyncResult)msg.obj; |
| 768 | request = (MainThreadRequest)ar.userObj; |
| 769 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 770 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 771 | break; |
| 772 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 773 | case CMD_SET_VOICEMAIL_NUMBER: |
| 774 | request = (MainThreadRequest) msg.obj; |
| 775 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 776 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 777 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 778 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 779 | break; |
| 780 | |
| 781 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 782 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 783 | break; |
| 784 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 785 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 786 | request = (MainThreadRequest) msg.obj; |
| 787 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 788 | request); |
| 789 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 790 | break; |
| 791 | |
| 792 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 793 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 794 | break; |
| 795 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 796 | case CMD_PERFORM_NETWORK_SCAN: |
| 797 | request = (MainThreadRequest) msg.obj; |
| 798 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 799 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 800 | break; |
| 801 | |
| 802 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 803 | ar = (AsyncResult) msg.obj; |
| 804 | request = (MainThreadRequest) ar.userObj; |
| 805 | CellNetworkScanResult cellScanResult; |
| 806 | if (ar.exception == null && ar.result != null) { |
| 807 | cellScanResult = new CellNetworkScanResult( |
| 808 | CellNetworkScanResult.STATUS_SUCCESS, |
| 809 | (List<OperatorInfo>) ar.result); |
| 810 | } else { |
| 811 | if (ar.result == null) { |
| 812 | loge("getCellNetworkScanResults: Empty response"); |
| 813 | } |
| 814 | if (ar.exception != null) { |
| 815 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 816 | } |
| 817 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 818 | if (ar.exception instanceof CommandException) { |
| 819 | CommandException.Error error = |
| 820 | ((CommandException) (ar.exception)).getCommandError(); |
| 821 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 822 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 823 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 824 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 825 | } |
| 826 | } |
| 827 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 828 | } |
| 829 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 830 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 831 | break; |
| 832 | |
| 833 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 834 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 835 | ManualNetworkSelectionArgument selArg = |
| 836 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 837 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 838 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 839 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 840 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 841 | break; |
| 842 | |
| 843 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 844 | ar = (AsyncResult) msg.obj; |
| 845 | request = (MainThreadRequest) ar.userObj; |
| 846 | if (ar.exception == null) { |
| 847 | request.result = true; |
| 848 | } else { |
| 849 | request.result = false; |
| 850 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 851 | } |
| 852 | notifyRequester(request); |
| 853 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 854 | break; |
| 855 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 856 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 857 | request = (MainThreadRequest) msg.obj; |
| 858 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 859 | if (defaultPhone != null) { |
| 860 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 861 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 862 | break; |
| 863 | |
| 864 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 865 | ar = (AsyncResult) msg.obj; |
| 866 | request = (MainThreadRequest) ar.userObj; |
| 867 | if (ar.exception == null && ar.result != null) { |
| 868 | request.result = ar.result; |
| 869 | } else { |
| 870 | if (ar.result == null) { |
| 871 | loge("queryModemActivityInfo: Empty response"); |
| 872 | } else if (ar.exception instanceof CommandException) { |
| 873 | loge("queryModemActivityInfo: CommandException: " + |
| 874 | ar.exception); |
| 875 | } else { |
| 876 | loge("queryModemActivityInfo: Unknown exception"); |
| 877 | } |
| 878 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 879 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 880 | if (request.result == null) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 881 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 882 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 883 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 884 | break; |
| 885 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 886 | case CMD_SET_ALLOWED_CARRIERS: |
| 887 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 888 | CarrierRestrictionRules argument = |
| 889 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 890 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 891 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 892 | break; |
| 893 | |
| 894 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 895 | ar = (AsyncResult) msg.obj; |
| 896 | request = (MainThreadRequest) ar.userObj; |
| 897 | if (ar.exception == null && ar.result != null) { |
| 898 | request.result = ar.result; |
| 899 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 900 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 901 | if (ar.exception instanceof CommandException) { |
| 902 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 903 | CommandException.Error error = |
| 904 | ((CommandException) (ar.exception)).getCommandError(); |
| 905 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 906 | request.result = |
| 907 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 908 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 909 | } else { |
| 910 | loge("setAllowedCarriers: Unknown exception"); |
| 911 | } |
| 912 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 913 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 914 | break; |
| 915 | |
| 916 | case CMD_GET_ALLOWED_CARRIERS: |
| 917 | request = (MainThreadRequest) msg.obj; |
| 918 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 919 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 920 | break; |
| 921 | |
| 922 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 923 | ar = (AsyncResult) msg.obj; |
| 924 | request = (MainThreadRequest) ar.userObj; |
| 925 | if (ar.exception == null && ar.result != null) { |
| 926 | request.result = ar.result; |
| 927 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 928 | request.result = new IllegalStateException( |
| 929 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 930 | if (ar.result == null) { |
| 931 | loge("getAllowedCarriers: Empty response"); |
| 932 | } else if (ar.exception instanceof CommandException) { |
| 933 | loge("getAllowedCarriers: CommandException: " + |
| 934 | ar.exception); |
| 935 | } else { |
| 936 | loge("getAllowedCarriers: Unknown exception"); |
| 937 | } |
| 938 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 939 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 940 | break; |
| 941 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 942 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 943 | ar = (AsyncResult) msg.obj; |
| 944 | request = (MainThreadRequest) ar.userObj; |
| 945 | if (ar.exception == null && ar.result != null) { |
| 946 | request.result = ar.result; |
| 947 | } else { |
| 948 | request.result = new IllegalArgumentException( |
| 949 | "Failed to retrieve Forbidden Plmns"); |
| 950 | if (ar.result == null) { |
| 951 | loge("getForbiddenPlmns: Empty response"); |
| 952 | } else { |
| 953 | loge("getForbiddenPlmns: Unknown exception"); |
| 954 | } |
| 955 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 956 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 957 | break; |
| 958 | |
| 959 | case CMD_GET_FORBIDDEN_PLMNS: |
| 960 | request = (MainThreadRequest) msg.obj; |
| 961 | uiccCard = getUiccCardFromRequest(request); |
| 962 | if (uiccCard == null) { |
| 963 | loge("getForbiddenPlmns() UiccCard is null"); |
| 964 | request.result = new IllegalArgumentException( |
| 965 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 966 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 967 | break; |
| 968 | } |
| 969 | Integer appType = (Integer) request.argument; |
| 970 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 971 | if (uiccApp == null) { |
| 972 | loge("getForbiddenPlmns() no app with specified type -- " |
| 973 | + appType); |
| 974 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 975 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 976 | break; |
| 977 | } else { |
| 978 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 979 | + " specified type -- " + appType); |
| 980 | } |
| 981 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 982 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 983 | onCompleted); |
| 984 | break; |
| 985 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 986 | case CMD_SWITCH_SLOTS: |
| 987 | request = (MainThreadRequest) msg.obj; |
| 988 | int[] physicalSlots = (int[]) request.argument; |
| 989 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 990 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 991 | break; |
| 992 | |
| 993 | case EVENT_SWITCH_SLOTS_DONE: |
| 994 | ar = (AsyncResult) msg.obj; |
| 995 | request = (MainThreadRequest) ar.userObj; |
| 996 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 997 | notifyRequester(request); |
| 998 | break; |
| 999 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1000 | request = (MainThreadRequest) msg.obj; |
| 1001 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1002 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1003 | break; |
| 1004 | |
| 1005 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1006 | ar = (AsyncResult) msg.obj; |
| 1007 | request = (MainThreadRequest) ar.userObj; |
| 1008 | if (ar.exception != null) { |
| 1009 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1010 | } else { |
| 1011 | int mode = ((int[]) ar.result)[0]; |
| 1012 | if (mode == 0) { |
| 1013 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1014 | } else { |
| 1015 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1016 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1017 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1018 | notifyRequester(request); |
| 1019 | break; |
| 1020 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1021 | request = (MainThreadRequest) msg.obj; |
| 1022 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1023 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1024 | break; |
| 1025 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1026 | ar = (AsyncResult) msg.obj; |
| 1027 | request = (MainThreadRequest) ar.userObj; |
| 1028 | if (ar.exception != null) { |
| 1029 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1030 | } else { |
| 1031 | request.result = ((int[]) ar.result)[0]; |
| 1032 | } |
| 1033 | notifyRequester(request); |
| 1034 | break; |
| 1035 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1036 | request = (MainThreadRequest) msg.obj; |
| 1037 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1038 | int mode = (int) request.argument; |
| 1039 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1040 | break; |
| 1041 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1042 | ar = (AsyncResult) msg.obj; |
| 1043 | request = (MainThreadRequest) ar.userObj; |
| 1044 | request.result = ar.exception == null; |
| 1045 | notifyRequester(request); |
| 1046 | break; |
| 1047 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1048 | request = (MainThreadRequest) msg.obj; |
| 1049 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1050 | int subscriptionMode = (int) request.argument; |
| 1051 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1052 | break; |
| 1053 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1054 | ar = (AsyncResult) msg.obj; |
| 1055 | request = (MainThreadRequest) ar.userObj; |
| 1056 | request.result = ar.exception == null; |
| 1057 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1058 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1059 | case CMD_GET_ALL_CELL_INFO: |
| 1060 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1061 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1062 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1063 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1064 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1065 | ar = (AsyncResult) msg.obj; |
| 1066 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1067 | // If a timeout occurs, the response will be null |
| 1068 | request.result = (ar.exception == null && ar.result != null) |
| 1069 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1070 | synchronized (request) { |
| 1071 | request.notifyAll(); |
| 1072 | } |
| 1073 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1074 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1075 | request = (MainThreadRequest) msg.obj; |
| 1076 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1077 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1078 | break; |
| 1079 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1080 | ar = (AsyncResult) msg.obj; |
| 1081 | request = (MainThreadRequest) ar.userObj; |
| 1082 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1083 | try { |
| 1084 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1085 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1086 | cb.onError( |
| 1087 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1088 | ar.exception.getClass().getName(), |
| 1089 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1090 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1091 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1092 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1093 | } else { |
| 1094 | // use the result as returned |
| 1095 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1096 | } |
| 1097 | } catch (RemoteException re) { |
| 1098 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1099 | } |
| 1100 | break; |
| 1101 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1102 | request = (MainThreadRequest) msg.obj; |
| 1103 | WorkSource ws = (WorkSource) request.argument; |
| 1104 | Phone phone = getPhoneFromRequest(request); |
| 1105 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1106 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1107 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1108 | ar = (AsyncResult) msg.obj; |
| 1109 | request = (MainThreadRequest) ar.userObj; |
| 1110 | if (ar.exception == null) { |
| 1111 | request.result = ar.result; |
| 1112 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1113 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1114 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1115 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1116 | } |
| 1117 | |
| 1118 | synchronized (request) { |
| 1119 | request.notifyAll(); |
| 1120 | } |
| 1121 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1122 | case CMD_MODEM_REBOOT: |
| 1123 | request = (MainThreadRequest) msg.obj; |
| 1124 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1125 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1126 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1127 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1128 | handleNullReturnEvent(msg, "rebootModem"); |
| 1129 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1130 | case CMD_REQUEST_ENABLE_MODEM: |
| 1131 | request = (MainThreadRequest) msg.obj; |
| 1132 | boolean enable = (boolean) request.argument; |
| 1133 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1134 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1135 | PhoneConfigurationManager.getInstance() |
| 1136 | .enablePhone(request.phone, enable, onCompleted); |
| 1137 | break; |
| 1138 | case EVENT_ENABLE_MODEM_DONE: |
| 1139 | ar = (AsyncResult) msg.obj; |
| 1140 | request = (MainThreadRequest) ar.userObj; |
| 1141 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1142 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1143 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1144 | if ((boolean) request.result) { |
| 1145 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1146 | updateModemStateMetrics(); |
| 1147 | } else { |
| 1148 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1149 | + ar.exception); |
| 1150 | } |
| 1151 | notifyRequester(request); |
| 1152 | break; |
| 1153 | case CMD_GET_MODEM_STATUS: |
| 1154 | request = (MainThreadRequest) msg.obj; |
| 1155 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1156 | PhoneConfigurationManager.getInstance() |
| 1157 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1158 | break; |
| 1159 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1160 | ar = (AsyncResult) msg.obj; |
| 1161 | request = (MainThreadRequest) ar.userObj; |
| 1162 | int id = request.phone.getPhoneId(); |
| 1163 | if (ar.exception == null && ar.result != null) { |
| 1164 | request.result = ar.result; |
| 1165 | //update the cache as modem status has changed |
| 1166 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1167 | (boolean) request.result); |
| 1168 | } else { |
| 1169 | // Return true if modem status cannot be retrieved. For most cases, |
| 1170 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1171 | // and disable modem are not supported. Modem is always on. |
| 1172 | // TODO: this should be fixed in R to support a third |
| 1173 | // status UNKNOWN b/131631629 |
| 1174 | request.result = true; |
| 1175 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1176 | + ar.exception); |
| 1177 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1178 | notifyRequester(request); |
| 1179 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1180 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1181 | ar = (AsyncResult) msg.obj; |
| 1182 | request = (MainThreadRequest) ar.userObj; |
| 1183 | if (ar.exception == null && ar.result != null) { |
| 1184 | request.result = ar.result; |
| 1185 | } else { |
| 1186 | request.result = -1; |
| 1187 | loge("Failed to set Forbidden Plmns"); |
| 1188 | if (ar.result == null) { |
| 1189 | loge("setForbidenPlmns: Empty response"); |
| 1190 | } else if (ar.exception != null) { |
| 1191 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1192 | request.result = -1; |
| 1193 | } else { |
| 1194 | loge("setForbiddenPlmns: Unknown exception"); |
| 1195 | } |
| 1196 | } |
| 1197 | notifyRequester(request); |
| 1198 | break; |
| 1199 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1200 | request = (MainThreadRequest) msg.obj; |
| 1201 | uiccCard = getUiccCardFromRequest(request); |
| 1202 | if (uiccCard == null) { |
| 1203 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1204 | request.result = -1; |
| 1205 | notifyRequester(request); |
| 1206 | break; |
| 1207 | } |
| 1208 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1209 | (Pair<Integer, List<String>>) request.argument; |
| 1210 | appType = setFplmnsArgs.first; |
| 1211 | List<String> fplmns = setFplmnsArgs.second; |
| 1212 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1213 | if (uiccApp == null) { |
| 1214 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1215 | request.result = -1; |
| 1216 | loge("Failed to get UICC App"); |
| 1217 | notifyRequester(request); |
| 1218 | } else { |
| 1219 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1220 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1221 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1222 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1223 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1224 | case CMD_ERASE_MODEM_CONFIG: |
| 1225 | request = (MainThreadRequest) msg.obj; |
| 1226 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1227 | defaultPhone.eraseModemConfig(onCompleted); |
| 1228 | break; |
| 1229 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1230 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1231 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1232 | default: |
| 1233 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1234 | break; |
| 1235 | } |
| 1236 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1237 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1238 | private void notifyRequester(MainThreadRequest request) { |
| 1239 | synchronized (request) { |
| 1240 | request.notifyAll(); |
| 1241 | } |
| 1242 | } |
| 1243 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1244 | private void handleNullReturnEvent(Message msg, String command) { |
| 1245 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1246 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1247 | if (ar.exception == null) { |
| 1248 | request.result = true; |
| 1249 | } else { |
| 1250 | request.result = false; |
| 1251 | if (ar.exception instanceof CommandException) { |
| 1252 | loge(command + ": CommandException: " + ar.exception); |
| 1253 | } else { |
| 1254 | loge(command + ": Unknown exception"); |
| 1255 | } |
| 1256 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1257 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1258 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /** |
| 1262 | * Posts the specified command to be executed on the main thread, |
| 1263 | * waits for the request to complete, and returns the result. |
| 1264 | * @see #sendRequestAsync |
| 1265 | */ |
| 1266 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1267 | return sendRequest( |
| 1268 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | /** |
| 1272 | * Posts the specified command to be executed on the main thread, |
| 1273 | * waits for the request to complete, and returns the result. |
| 1274 | * @see #sendRequestAsync |
| 1275 | */ |
| 1276 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1277 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1278 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Posts the specified command to be executed on the main thread, |
| 1283 | * waits for the request to complete, and returns the result. |
| 1284 | * @see #sendRequestAsync |
| 1285 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1286 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1287 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | /** |
| 1291 | * Posts the specified command to be executed on the main thread, |
| 1292 | * waits for the request to complete, and returns the result. |
| 1293 | * @see #sendRequestAsync |
| 1294 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1295 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1296 | return sendRequest(command, argument, subId, null, workSource); |
| 1297 | } |
| 1298 | |
| 1299 | /** |
| 1300 | * Posts the specified command to be executed on the main thread, |
| 1301 | * waits for the request to complete, and returns the result. |
| 1302 | * @see #sendRequestAsync |
| 1303 | */ |
| 1304 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1305 | return sendRequest( |
| 1306 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1307 | } |
| 1308 | |
| 1309 | /** |
| 1310 | * Posts the specified command to be executed on the main thread, |
| 1311 | * waits for the request to complete, and returns the result. |
| 1312 | * @see #sendRequestAsync |
| 1313 | */ |
| 1314 | private Object sendRequest( |
| 1315 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1316 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1317 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1318 | } |
| 1319 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1320 | MainThreadRequest request = null; |
| 1321 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1322 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1323 | } else if (phone != null) { |
| 1324 | request = new MainThreadRequest(argument, phone, workSource); |
| 1325 | } else { |
| 1326 | request = new MainThreadRequest(argument, subId, workSource); |
| 1327 | } |
| 1328 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1329 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1330 | msg.sendToTarget(); |
| 1331 | |
| 1332 | // Wait for the request to complete |
| 1333 | synchronized (request) { |
| 1334 | while (request.result == null) { |
| 1335 | try { |
| 1336 | request.wait(); |
| 1337 | } catch (InterruptedException e) { |
| 1338 | // Do nothing, go back and wait until the request is complete |
| 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | return request.result; |
| 1343 | } |
| 1344 | |
| 1345 | /** |
| 1346 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1347 | * Posts the specified command to be executed on the main thread, and |
| 1348 | * returns immediately. |
| 1349 | * @see #sendRequest |
| 1350 | */ |
| 1351 | private void sendRequestAsync(int command) { |
| 1352 | mMainThreadHandler.sendEmptyMessage(command); |
| 1353 | } |
| 1354 | |
| 1355 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1356 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1357 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1358 | */ |
| 1359 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1360 | sendRequestAsync(command, argument, null, null); |
| 1361 | } |
| 1362 | |
| 1363 | /** |
| 1364 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1365 | * @see {@link #sendRequest(int,Object)} |
| 1366 | */ |
| 1367 | private void sendRequestAsync( |
| 1368 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1369 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1370 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1371 | msg.sendToTarget(); |
| 1372 | } |
| 1373 | |
| 1374 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1375 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1376 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1377 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1378 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1379 | synchronized (PhoneInterfaceManager.class) { |
| 1380 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1381 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1382 | } else { |
| 1383 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1384 | } |
| 1385 | return sInstance; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1390 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1391 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1392 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1393 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1394 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1395 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1396 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1397 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1398 | mTelephonySharedPreferences = |
| 1399 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1400 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1401 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1402 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1403 | publish(); |
| 1404 | } |
| 1405 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1406 | private Phone getDefaultPhone() { |
| 1407 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1408 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1409 | } |
| 1410 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1411 | private void publish() { |
| 1412 | if (DBG) log("publish: " + this); |
| 1413 | |
| 1414 | ServiceManager.addService("phone", this); |
| 1415 | } |
| 1416 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1417 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1418 | if (request.phone != null) { |
| 1419 | return request.phone; |
| 1420 | } else { |
| 1421 | return getPhoneFromSubId(request.subId); |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | private Phone getPhoneFromSubId(int subId) { |
| 1426 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1427 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1430 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1431 | Phone phone = getPhoneFromRequest(request); |
| 1432 | return phone == null ? null : |
| 1433 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1434 | } |
| 1435 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1436 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1437 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1438 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1439 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1440 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1441 | private void sendEraseModemConfig(Phone phone) { |
| 1442 | if (phone != null) { |
| 1443 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1444 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1445 | final long identity = Binder.clearCallingIdentity(); |
| 1446 | try { |
| 1447 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1448 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1449 | } finally { |
| 1450 | Binder.restoreCallingIdentity(identity); |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| 1454 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1455 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1456 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1459 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1460 | if (DBG) log("dial: " + number); |
| 1461 | // No permission check needed here: This is just a wrapper around the |
| 1462 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1463 | // the UI before it does anything. |
| 1464 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1465 | final long identity = Binder.clearCallingIdentity(); |
| 1466 | try { |
| 1467 | String url = createTelUrl(number); |
| 1468 | if (url == null) { |
| 1469 | return; |
| 1470 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1472 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1473 | PhoneConstants.State state = mCM.getState(subId); |
| 1474 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1475 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1476 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1477 | mApp.startActivity(intent); |
| 1478 | } |
| 1479 | } finally { |
| 1480 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1485 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1488 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1489 | if (DBG) log("call: " + number); |
| 1490 | |
| 1491 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1492 | // need to do a permission check since we're calling startActivity() |
| 1493 | // from the context of the phone app. |
| 1494 | enforceCallPermission(); |
| 1495 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1496 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1497 | != AppOpsManager.MODE_ALLOWED) { |
| 1498 | return; |
| 1499 | } |
| 1500 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1501 | final long identity = Binder.clearCallingIdentity(); |
| 1502 | try { |
| 1503 | String url = createTelUrl(number); |
| 1504 | if (url == null) { |
| 1505 | return; |
| 1506 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1507 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1508 | boolean isValid = false; |
| 1509 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1510 | if (slist != null) { |
| 1511 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1512 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1513 | isValid = true; |
| 1514 | break; |
| 1515 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1516 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1517 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1518 | if (!isValid) { |
| 1519 | return; |
| 1520 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1521 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1522 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1523 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1524 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1525 | mApp.startActivity(intent); |
| 1526 | } finally { |
| 1527 | Binder.restoreCallingIdentity(identity); |
| 1528 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1531 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1532 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1535 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1536 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1537 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1538 | } |
| 1539 | |
| 1540 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1541 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1544 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1545 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1546 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1547 | } |
| 1548 | |
| 1549 | /** {@hide} */ |
| 1550 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1551 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1554 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1555 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1556 | |
| 1557 | final long identity = Binder.clearCallingIdentity(); |
| 1558 | try { |
| 1559 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1560 | checkSimPin.start(); |
| 1561 | return checkSimPin.unlockSim(null, pin); |
| 1562 | } finally { |
| 1563 | Binder.restoreCallingIdentity(identity); |
| 1564 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1567 | /** {@hide} */ |
| 1568 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1569 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1572 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1573 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1574 | |
| 1575 | final long identity = Binder.clearCallingIdentity(); |
| 1576 | try { |
| 1577 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1578 | checkSimPuk.start(); |
| 1579 | return checkSimPuk.unlockSim(puk, pin); |
| 1580 | } finally { |
| 1581 | Binder.restoreCallingIdentity(identity); |
| 1582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1586 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1587 | * a synchronous one. |
| 1588 | */ |
| 1589 | private static class UnlockSim extends Thread { |
| 1590 | |
| 1591 | private final IccCard mSimCard; |
| 1592 | |
| 1593 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1594 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1595 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1596 | |
| 1597 | // For replies from SimCard interface |
| 1598 | private Handler mHandler; |
| 1599 | |
| 1600 | // For async handler to identify request type |
| 1601 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1602 | |
| 1603 | public UnlockSim(IccCard simCard) { |
| 1604 | mSimCard = simCard; |
| 1605 | } |
| 1606 | |
| 1607 | @Override |
| 1608 | public void run() { |
| 1609 | Looper.prepare(); |
| 1610 | synchronized (UnlockSim.this) { |
| 1611 | mHandler = new Handler() { |
| 1612 | @Override |
| 1613 | public void handleMessage(Message msg) { |
| 1614 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1615 | switch (msg.what) { |
| 1616 | case SUPPLY_PIN_COMPLETE: |
| 1617 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1618 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1619 | mRetryCount = msg.arg1; |
| 1620 | if (ar.exception != null) { |
| 1621 | if (ar.exception instanceof CommandException && |
| 1622 | ((CommandException)(ar.exception)).getCommandError() |
| 1623 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1624 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1625 | } else { |
| 1626 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1627 | } |
| 1628 | } else { |
| 1629 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1631 | mDone = true; |
| 1632 | UnlockSim.this.notifyAll(); |
| 1633 | } |
| 1634 | break; |
| 1635 | } |
| 1636 | } |
| 1637 | }; |
| 1638 | UnlockSim.this.notifyAll(); |
| 1639 | } |
| 1640 | Looper.loop(); |
| 1641 | } |
| 1642 | |
| 1643 | /* |
| 1644 | * Use PIN or PUK to unlock SIM card |
| 1645 | * |
| 1646 | * If PUK is null, unlock SIM card with PIN |
| 1647 | * |
| 1648 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1649 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1650 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1651 | |
| 1652 | while (mHandler == null) { |
| 1653 | try { |
| 1654 | wait(); |
| 1655 | } catch (InterruptedException e) { |
| 1656 | Thread.currentThread().interrupt(); |
| 1657 | } |
| 1658 | } |
| 1659 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1660 | |
| 1661 | if (puk == null) { |
| 1662 | mSimCard.supplyPin(pin, callback); |
| 1663 | } else { |
| 1664 | mSimCard.supplyPuk(puk, pin, callback); |
| 1665 | } |
| 1666 | |
| 1667 | while (!mDone) { |
| 1668 | try { |
| 1669 | Log.d(LOG_TAG, "wait for done"); |
| 1670 | wait(); |
| 1671 | } catch (InterruptedException e) { |
| 1672 | // Restore the interrupted status |
| 1673 | Thread.currentThread().interrupt(); |
| 1674 | } |
| 1675 | } |
| 1676 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1677 | int[] resultArray = new int[2]; |
| 1678 | resultArray[0] = mResult; |
| 1679 | resultArray[1] = mRetryCount; |
| 1680 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1685 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1686 | |
| 1687 | } |
| 1688 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1689 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1690 | // No permission check needed here: this call is harmless, and it's |
| 1691 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1692 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1693 | final long identity = Binder.clearCallingIdentity(); |
| 1694 | try { |
| 1695 | final Phone phone = getPhone(subId); |
| 1696 | if (phone != null) { |
| 1697 | phone.updateServiceLocation(); |
| 1698 | } |
| 1699 | } finally { |
| 1700 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1701 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1704 | @Override |
| 1705 | public boolean isRadioOn(String callingPackage) { |
| 1706 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1709 | @Override |
| 1710 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1711 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1712 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1713 | return false; |
| 1714 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1715 | |
| 1716 | final long identity = Binder.clearCallingIdentity(); |
| 1717 | try { |
| 1718 | return isRadioOnForSubscriber(subId); |
| 1719 | } finally { |
| 1720 | Binder.restoreCallingIdentity(identity); |
| 1721 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1725 | final long identity = Binder.clearCallingIdentity(); |
| 1726 | try { |
| 1727 | final Phone phone = getPhone(subId); |
| 1728 | if (phone != null) { |
| 1729 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1730 | } else { |
| 1731 | return false; |
| 1732 | } |
| 1733 | } finally { |
| 1734 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1735 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1739 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1740 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1741 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1742 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1743 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1744 | |
| 1745 | final long identity = Binder.clearCallingIdentity(); |
| 1746 | try { |
| 1747 | final Phone phone = getPhone(subId); |
| 1748 | if (phone != null) { |
| 1749 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1750 | } |
| 1751 | } finally { |
| 1752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1753 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1757 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1760 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1761 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1762 | |
| 1763 | final long identity = Binder.clearCallingIdentity(); |
| 1764 | try { |
| 1765 | final Phone phone = getPhone(subId); |
| 1766 | if (phone == null) { |
| 1767 | return false; |
| 1768 | } |
| 1769 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1770 | toggleRadioOnOffForSubscriber(subId); |
| 1771 | } |
| 1772 | return true; |
| 1773 | } finally { |
| 1774 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1775 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1776 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1777 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1778 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1779 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1780 | /* |
| 1781 | * If any of the Radios are available, it will need to be |
| 1782 | * shutdown. So return true if any Radio is available. |
| 1783 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1784 | final long identity = Binder.clearCallingIdentity(); |
| 1785 | try { |
| 1786 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1787 | Phone phone = PhoneFactory.getPhone(i); |
| 1788 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1789 | } |
| 1790 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1791 | return false; |
| 1792 | } finally { |
| 1793 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1794 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1797 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1798 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1799 | enforceModifyPermission(); |
| 1800 | |
| 1801 | final long identity = Binder.clearCallingIdentity(); |
| 1802 | try { |
| 1803 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1804 | logv("Shutting down Phone " + i); |
| 1805 | shutdownRadioUsingPhoneId(i); |
| 1806 | } |
| 1807 | } finally { |
| 1808 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1813 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1814 | if (phone != null && phone.isRadioAvailable()) { |
| 1815 | phone.shutdownRadio(); |
| 1816 | } |
| 1817 | } |
| 1818 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1819 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -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 Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1825 | if (defaultPhone != null) { |
| 1826 | defaultPhone.setRadioPower(turnOn); |
| 1827 | return true; |
| 1828 | } else { |
| 1829 | loge("There's no default phone."); |
| 1830 | return false; |
| 1831 | } |
| 1832 | } finally { |
| 1833 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1834 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1837 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1838 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1839 | |
| 1840 | final long identity = Binder.clearCallingIdentity(); |
| 1841 | try { |
| 1842 | final Phone phone = getPhone(subId); |
| 1843 | if (phone != null) { |
| 1844 | phone.setRadioPower(turnOn); |
| 1845 | return true; |
| 1846 | } else { |
| 1847 | return false; |
| 1848 | } |
| 1849 | } finally { |
| 1850 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1851 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1854 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1855 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1856 | public boolean enableDataConnectivity() { |
| 1857 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1858 | |
| 1859 | final long identity = Binder.clearCallingIdentity(); |
| 1860 | try { |
| 1861 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1862 | final Phone phone = getPhone(subId); |
| 1863 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1864 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1865 | return true; |
| 1866 | } else { |
| 1867 | return false; |
| 1868 | } |
| 1869 | } finally { |
| 1870 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1871 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1874 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1875 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1876 | public boolean disableDataConnectivity() { |
| 1877 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1878 | |
| 1879 | final long identity = Binder.clearCallingIdentity(); |
| 1880 | try { |
| 1881 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1882 | final Phone phone = getPhone(subId); |
| 1883 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1884 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1885 | return true; |
| 1886 | } else { |
| 1887 | return false; |
| 1888 | } |
| 1889 | } finally { |
| 1890 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1891 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1894 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1895 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1896 | final long identity = Binder.clearCallingIdentity(); |
| 1897 | try { |
| 1898 | final Phone phone = getPhone(subId); |
| 1899 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1900 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1901 | } else { |
| 1902 | return false; |
| 1903 | } |
| 1904 | } finally { |
| 1905 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1906 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1910 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1913 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1914 | enforceCallPermission(); |
| 1915 | |
| 1916 | final long identity = Binder.clearCallingIdentity(); |
| 1917 | try { |
| 1918 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1919 | return; |
| 1920 | } |
| 1921 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1922 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1923 | } finally { |
| 1924 | Binder.restoreCallingIdentity(identity); |
| 1925 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1926 | }; |
| 1927 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1928 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1929 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1930 | |
| 1931 | final long identity = Binder.clearCallingIdentity(); |
| 1932 | try { |
| 1933 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1934 | return false; |
| 1935 | } |
| 1936 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1937 | } finally { |
| 1938 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1939 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1943 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1946 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1947 | final long identity = Binder.clearCallingIdentity(); |
| 1948 | try { |
| 1949 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1950 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1951 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1952 | } finally { |
| 1953 | Binder.restoreCallingIdentity(identity); |
| 1954 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1957 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1958 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1959 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1960 | } |
| 1961 | |
| 1962 | @Override |
| 1963 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1964 | final long identity = Binder.clearCallingIdentity(); |
| 1965 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1966 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1967 | if (phone != null) { |
| 1968 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1969 | } else { |
| 1970 | return PhoneConstantConversions.convertDataState( |
| 1971 | PhoneConstants.DataState.DISCONNECTED); |
| 1972 | } |
| 1973 | } finally { |
| 1974 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1975 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1978 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1979 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1980 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1981 | } |
| 1982 | |
| 1983 | @Override |
| 1984 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1985 | final long identity = Binder.clearCallingIdentity(); |
| 1986 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1987 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1988 | if (phone != null) { |
| 1989 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1990 | } else { |
| 1991 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1992 | } |
| 1993 | } finally { |
| 1994 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1995 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1999 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2000 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2001 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2002 | |
| 2003 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2004 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2005 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2006 | .setCallingPackage(callingPackage) |
| 2007 | .setCallingPid(Binder.getCallingPid()) |
| 2008 | .setCallingUid(Binder.getCallingUid()) |
| 2009 | .setMethod("getCellLocation") |
| 2010 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2011 | .build()); |
| 2012 | switch (locationResult) { |
| 2013 | case DENIED_HARD: |
| 2014 | throw new SecurityException("Not allowed to access cell location"); |
| 2015 | case DENIED_SOFT: |
| 2016 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2019 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2020 | final long identity = Binder.clearCallingIdentity(); |
| 2021 | try { |
| 2022 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 2023 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2024 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2025 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 2026 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2027 | return data; |
| 2028 | } finally { |
| 2029 | Binder.restoreCallingIdentity(identity); |
| 2030 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2033 | @Override |
Jack Yu | 7c5d91a | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2034 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) { |
| 2035 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2036 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| 2037 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2038 | mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) { |
| 2039 | return ""; |
| 2040 | } |
| 2041 | } |
| 2042 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2043 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2044 | // registered cell info, so return a NULL country instead. |
| 2045 | final long identity = Binder.clearCallingIdentity(); |
| 2046 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2047 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2048 | // Get default phone in this case. |
| 2049 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2050 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2051 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2052 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2053 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2054 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 2055 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 2056 | return ""; |
| 2057 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2058 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2059 | if (phone != null) { |
| 2060 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2061 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2062 | if (sst != null) { |
| 2063 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2064 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2065 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2066 | return lt.getCurrentCountry(); |
| 2067 | } else if (emergencyNumberTracker != null) { |
| 2068 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2070 | } |
| 2071 | } |
| 2072 | } |
| 2073 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2074 | } finally { |
| 2075 | Binder.restoreCallingIdentity(identity); |
| 2076 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2080 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2081 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2084 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2085 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2086 | mApp.enforceCallingOrSelfPermission( |
| 2087 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2088 | |
| 2089 | final long identity = Binder.clearCallingIdentity(); |
| 2090 | try { |
| 2091 | final Phone phone = getPhone(subId); |
| 2092 | if (phone != null) { |
| 2093 | phone.enableLocationUpdates(); |
| 2094 | } |
| 2095 | } finally { |
| 2096 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2097 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | @Override |
| 2101 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2102 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2105 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2106 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | mApp.enforceCallingOrSelfPermission( |
| 2108 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2109 | |
| 2110 | final long identity = Binder.clearCallingIdentity(); |
| 2111 | try { |
| 2112 | final Phone phone = getPhone(subId); |
| 2113 | if (phone != null) { |
| 2114 | phone.disableLocationUpdates(); |
| 2115 | } |
| 2116 | } finally { |
| 2117 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2118 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2121 | /** |
| 2122 | * Returns the target SDK version number for a given package name. |
| 2123 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2124 | * This call MUST be invoked before clearing the calling UID. |
| 2125 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2126 | * @return target SDK if the package is found or INT_MAX. |
| 2127 | */ |
| 2128 | private int getTargetSdk(String packageName) { |
| 2129 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2130 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2131 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2132 | if (ai != null) return ai.targetSdkVersion; |
| 2133 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2134 | loge("Failed to get package info for pkg=" |
| 2135 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2136 | } |
| 2137 | return Integer.MAX_VALUE; |
| 2138 | } |
| 2139 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | @Override |
| 2141 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2142 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2143 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2144 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2145 | throw new SecurityException( |
| 2146 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2147 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2148 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2149 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2150 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2151 | return null; |
| 2152 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2153 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2154 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2155 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2156 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2157 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2158 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2159 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2160 | for (CellInfo ci : info) { |
| 2161 | if (ci instanceof CellInfoGsm) { |
| 2162 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2163 | } else if (ci instanceof CellInfoWcdma) { |
| 2164 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2165 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2167 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2170 | private List<CellInfo> getCachedCellInfo() { |
| 2171 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2172 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2173 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2174 | if (info != null) cellInfos.addAll(info); |
| 2175 | } |
| 2176 | return cellInfos; |
| 2177 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | |
| 2179 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2180 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2181 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2182 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2183 | |
| 2184 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2185 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2186 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2187 | .setCallingPackage(callingPackage) |
| 2188 | .setCallingPid(Binder.getCallingPid()) |
| 2189 | .setCallingUid(Binder.getCallingUid()) |
| 2190 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2191 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2192 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2193 | .build()); |
| 2194 | switch (locationResult) { |
| 2195 | case DENIED_HARD: |
| 2196 | throw new SecurityException("Not allowed to access cell info"); |
| 2197 | case DENIED_SOFT: |
| 2198 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2201 | final int targetSdk = getTargetSdk(callingPackage); |
| 2202 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2203 | return getCachedCellInfo(); |
| 2204 | } |
| 2205 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2206 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2207 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2208 | final long identity = Binder.clearCallingIdentity(); |
| 2209 | try { |
| 2210 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2211 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2212 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2213 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2214 | if (info != null) cellInfos.addAll(info); |
| 2215 | } |
| 2216 | return cellInfos; |
| 2217 | } finally { |
| 2218 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2219 | } |
| 2220 | } |
| 2221 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2222 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2223 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2224 | requestCellInfoUpdateInternal( |
| 2225 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2226 | } |
| 2227 | |
| 2228 | @Override |
| 2229 | public void requestCellInfoUpdateWithWorkSource( |
| 2230 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2231 | enforceModifyPermission(); |
| 2232 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2233 | } |
| 2234 | |
| 2235 | private void requestCellInfoUpdateInternal( |
| 2236 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2237 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2238 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2239 | |
| 2240 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2241 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2242 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2243 | .setCallingPackage(callingPackage) |
| 2244 | .setCallingPid(Binder.getCallingPid()) |
| 2245 | .setCallingUid(Binder.getCallingUid()) |
| 2246 | .setMethod("requestCellInfoUpdate") |
| 2247 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2248 | .build()); |
| 2249 | switch (locationResult) { |
| 2250 | case DENIED_HARD: |
| 2251 | throw new SecurityException("Not allowed to access cell info"); |
| 2252 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2253 | try { |
| 2254 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2255 | } catch (RemoteException re) { |
| 2256 | // Drop without consequences |
| 2257 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2258 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2261 | |
| 2262 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2263 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2264 | |
| 2265 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2266 | } |
| 2267 | |
| 2268 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2269 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2270 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2271 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2272 | |
| 2273 | final long identity = Binder.clearCallingIdentity(); |
| 2274 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2275 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2276 | } finally { |
| 2277 | Binder.restoreCallingIdentity(identity); |
| 2278 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2281 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2282 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2283 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2284 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2285 | return null; |
| 2286 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2287 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2288 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2289 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2290 | return null; |
| 2291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 | |
| 2293 | final long identity = Binder.clearCallingIdentity(); |
| 2294 | try { |
| 2295 | return phone.getImei(); |
| 2296 | } finally { |
| 2297 | Binder.restoreCallingIdentity(identity); |
| 2298 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2302 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2303 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2304 | String tac = null; |
| 2305 | if (phone != null) { |
| 2306 | String imei = phone.getImei(); |
| 2307 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2308 | } |
| 2309 | return tac; |
| 2310 | } |
| 2311 | |
| 2312 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2313 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2314 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2315 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2316 | return null; |
| 2317 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2318 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2319 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2320 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2321 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2322 | return null; |
| 2323 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2324 | |
| 2325 | final long identity = Binder.clearCallingIdentity(); |
| 2326 | try { |
| 2327 | return phone.getMeid(); |
| 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(identity); |
| 2330 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2334 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2335 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2336 | String manufacturerCode = null; |
| 2337 | if (phone != null) { |
| 2338 | String meid = phone.getMeid(); |
| 2339 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2340 | } |
| 2341 | return manufacturerCode; |
| 2342 | } |
| 2343 | |
| 2344 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2345 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2346 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2347 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2348 | return null; |
| 2349 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2350 | int subId = phone.getSubId(); |
| 2351 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2352 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2353 | return null; |
| 2354 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2355 | |
| 2356 | final long identity = Binder.clearCallingIdentity(); |
| 2357 | try { |
| 2358 | return phone.getDeviceSvn(); |
| 2359 | } finally { |
| 2360 | Binder.restoreCallingIdentity(identity); |
| 2361 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2364 | @Override |
| 2365 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2366 | final long identity = Binder.clearCallingIdentity(); |
| 2367 | try { |
| 2368 | final Phone phone = getPhone(subId); |
| 2369 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2370 | } finally { |
| 2371 | Binder.restoreCallingIdentity(identity); |
| 2372 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | @Override |
| 2376 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2377 | final long identity = Binder.clearCallingIdentity(); |
| 2378 | try { |
| 2379 | final Phone phone = getPhone(subId); |
| 2380 | return phone == null ? null : phone.getCarrierName(); |
| 2381 | } finally { |
| 2382 | Binder.restoreCallingIdentity(identity); |
| 2383 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2384 | } |
| 2385 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2386 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2387 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2388 | final long identity = Binder.clearCallingIdentity(); |
| 2389 | try { |
| 2390 | final Phone phone = getPhone(subId); |
| 2391 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2392 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2393 | } finally { |
| 2394 | Binder.restoreCallingIdentity(identity); |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2399 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2400 | final long identity = Binder.clearCallingIdentity(); |
| 2401 | try { |
| 2402 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2403 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2404 | } finally { |
| 2405 | Binder.restoreCallingIdentity(identity); |
| 2406 | } |
| 2407 | } |
| 2408 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2409 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2410 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2411 | if (!isSubscriptionMccMnc) { |
| 2412 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2413 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2414 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2415 | if (phone == null) { |
| 2416 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2417 | } |
| 2418 | final long identity = Binder.clearCallingIdentity(); |
| 2419 | try { |
| 2420 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2421 | } finally { |
| 2422 | Binder.restoreCallingIdentity(identity); |
| 2423 | } |
| 2424 | } |
| 2425 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | // |
| 2427 | // Internal helper methods. |
| 2428 | // |
| 2429 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2430 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2432 | * |
| 2433 | * @throws SecurityException if the caller does not have the required permission |
| 2434 | */ |
| 2435 | private void enforceModifyPermission() { |
| 2436 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2437 | } |
| 2438 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2439 | private void enforceActiveEmergencySessionPermission() { |
| 2440 | mApp.enforceCallingOrSelfPermission( |
| 2441 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2442 | } |
| 2443 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2444 | /** |
| 2445 | * Make sure the caller has the CALL_PHONE permission. |
| 2446 | * |
| 2447 | * @throws SecurityException if the caller does not have the required permission |
| 2448 | */ |
| 2449 | private void enforceCallPermission() { |
| 2450 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2451 | } |
| 2452 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2453 | private void enforceSettingsPermission() { |
| 2454 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | private String createTelUrl(String number) { |
| 2458 | if (TextUtils.isEmpty(number)) { |
| 2459 | return null; |
| 2460 | } |
| 2461 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2462 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2465 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2467 | } |
| 2468 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2469 | private static void logv(String msg) { |
| 2470 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2471 | } |
| 2472 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2473 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2474 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2475 | } |
| 2476 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2477 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2479 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2482 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2483 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2484 | final long identity = Binder.clearCallingIdentity(); |
| 2485 | try { |
| 2486 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2487 | if (phone == null) { |
| 2488 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2489 | } else { |
| 2490 | return phone.getPhoneType(); |
| 2491 | } |
| 2492 | } finally { |
| 2493 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2494 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | /** |
| 2498 | * Returns the CDMA ERI icon index to display |
| 2499 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2500 | @Override |
| 2501 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2502 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2505 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2506 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2507 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2508 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2509 | return -1; |
| 2510 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | |
| 2512 | final long identity = Binder.clearCallingIdentity(); |
| 2513 | try { |
| 2514 | final Phone phone = getPhone(subId); |
| 2515 | if (phone != null) { |
| 2516 | return phone.getCdmaEriIconIndex(); |
| 2517 | } else { |
| 2518 | return -1; |
| 2519 | } |
| 2520 | } finally { |
| 2521 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2522 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | /** |
| 2526 | * Returns the CDMA ERI icon mode, |
| 2527 | * 0 - ON |
| 2528 | * 1 - FLASHING |
| 2529 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2530 | @Override |
| 2531 | public int getCdmaEriIconMode(String callingPackage) { |
| 2532 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2533 | } |
| 2534 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2535 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2536 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2537 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2538 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2539 | return -1; |
| 2540 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2541 | |
| 2542 | final long identity = Binder.clearCallingIdentity(); |
| 2543 | try { |
| 2544 | final Phone phone = getPhone(subId); |
| 2545 | if (phone != null) { |
| 2546 | return phone.getCdmaEriIconMode(); |
| 2547 | } else { |
| 2548 | return -1; |
| 2549 | } |
| 2550 | } finally { |
| 2551 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2552 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | /** |
| 2556 | * Returns the CDMA ERI text, |
| 2557 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2558 | @Override |
| 2559 | public String getCdmaEriText(String callingPackage) { |
| 2560 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2563 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2564 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2565 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2566 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2567 | return null; |
| 2568 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | |
| 2570 | final long identity = Binder.clearCallingIdentity(); |
| 2571 | try { |
| 2572 | final Phone phone = getPhone(subId); |
| 2573 | if (phone != null) { |
| 2574 | return phone.getCdmaEriText(); |
| 2575 | } else { |
| 2576 | return null; |
| 2577 | } |
| 2578 | } finally { |
| 2579 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2580 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2584 | * Returns the CDMA MDN. |
| 2585 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2586 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2587 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2589 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | |
| 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
| 2593 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2594 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 | return phone.getLine1Number(); |
| 2596 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2597 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | return null; |
| 2599 | } |
| 2600 | } finally { |
| 2601 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | /** |
| 2606 | * Returns the CDMA MIN. |
| 2607 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2608 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2609 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2610 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2611 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | |
| 2613 | final long identity = Binder.clearCallingIdentity(); |
| 2614 | try { |
| 2615 | final Phone phone = getPhone(subId); |
| 2616 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2617 | return phone.getCdmaMin(); |
| 2618 | } else { |
| 2619 | return null; |
| 2620 | } |
| 2621 | } finally { |
| 2622 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2623 | } |
| 2624 | } |
| 2625 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2626 | @Override |
| 2627 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2628 | INumberVerificationCallback callback, String callingPackage) { |
| 2629 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2630 | != PERMISSION_GRANTED) { |
| 2631 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2632 | } |
| 2633 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2634 | |
| 2635 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2636 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2637 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2638 | } |
| 2639 | |
| 2640 | if (range == null) { |
| 2641 | throw new NullPointerException("Range must be non-null"); |
| 2642 | } |
| 2643 | |
| 2644 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2645 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2646 | |
| 2647 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2648 | } |
| 2649 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2650 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2651 | * Returns true if CDMA provisioning needs to run. |
| 2652 | */ |
| 2653 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | final long identity = Binder.clearCallingIdentity(); |
| 2655 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2656 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | } finally { |
| 2658 | Binder.restoreCallingIdentity(identity); |
| 2659 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2663 | * Sets the voice mail number of a given subId. |
| 2664 | */ |
| 2665 | @Override |
| 2666 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2667 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | |
| 2669 | final long identity = Binder.clearCallingIdentity(); |
| 2670 | try { |
| 2671 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2672 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2673 | return success; |
| 2674 | } finally { |
| 2675 | Binder.restoreCallingIdentity(identity); |
| 2676 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2677 | } |
| 2678 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2679 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2680 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2681 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2682 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2683 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2684 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2685 | throw new SecurityException("caller must be system dialer"); |
| 2686 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | |
| 2688 | final long identity = Binder.clearCallingIdentity(); |
| 2689 | try { |
| 2690 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2691 | if (phoneAccountHandle == null) { |
| 2692 | return null; |
| 2693 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2694 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | } finally { |
| 2696 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2697 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2701 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2702 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2703 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2704 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2705 | return null; |
| 2706 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2707 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2708 | final long identity = Binder.clearCallingIdentity(); |
| 2709 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2710 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2711 | } finally { |
| 2712 | Binder.restoreCallingIdentity(identity); |
| 2713 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2717 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2718 | VisualVoicemailSmsFilterSettings settings) { |
| 2719 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2720 | |
| 2721 | final long identity = Binder.clearCallingIdentity(); |
| 2722 | try { |
| 2723 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2724 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2725 | } finally { |
| 2726 | Binder.restoreCallingIdentity(identity); |
| 2727 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2731 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2732 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2733 | |
| 2734 | final long identity = Binder.clearCallingIdentity(); |
| 2735 | try { |
| 2736 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2737 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2738 | } finally { |
| 2739 | Binder.restoreCallingIdentity(identity); |
| 2740 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2744 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2745 | String callingPackage, int subId) { |
| 2746 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2747 | |
| 2748 | final long identity = Binder.clearCallingIdentity(); |
| 2749 | try { |
| 2750 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2751 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2752 | } finally { |
| 2753 | Binder.restoreCallingIdentity(identity); |
| 2754 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2758 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2759 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | |
| 2761 | final long identity = Binder.clearCallingIdentity(); |
| 2762 | try { |
| 2763 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2764 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | } finally { |
| 2766 | Binder.restoreCallingIdentity(identity); |
| 2767 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | @Override |
| 2771 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2772 | String number, int port, String text, PendingIntent sentIntent) { |
| 2773 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2774 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2775 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2776 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2777 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2778 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2779 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2780 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2781 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2782 | * Sets the voice activation state of a given subId. |
| 2783 | */ |
| 2784 | @Override |
| 2785 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2786 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2787 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2788 | |
| 2789 | final long identity = Binder.clearCallingIdentity(); |
| 2790 | try { |
| 2791 | final Phone phone = getPhone(subId); |
| 2792 | if (phone != null) { |
| 2793 | phone.setVoiceActivationState(activationState); |
| 2794 | } else { |
| 2795 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2796 | } |
| 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | /** |
| 2803 | * Sets the data activation state of a given subId. |
| 2804 | */ |
| 2805 | @Override |
| 2806 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2807 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2808 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2809 | |
| 2810 | final long identity = Binder.clearCallingIdentity(); |
| 2811 | try { |
| 2812 | final Phone phone = getPhone(subId); |
| 2813 | if (phone != null) { |
| 2814 | phone.setDataActivationState(activationState); |
| 2815 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2816 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2817 | } |
| 2818 | } finally { |
| 2819 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | /** |
| 2824 | * Returns the voice activation state of a given subId. |
| 2825 | */ |
| 2826 | @Override |
| 2827 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2828 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2830 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2831 | final long identity = Binder.clearCallingIdentity(); |
| 2832 | try { |
| 2833 | if (phone != null) { |
| 2834 | return phone.getVoiceActivationState(); |
| 2835 | } else { |
| 2836 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2837 | } |
| 2838 | } finally { |
| 2839 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | /** |
| 2844 | * Returns the data activation state of a given subId. |
| 2845 | */ |
| 2846 | @Override |
| 2847 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2848 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2849 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2850 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | final long identity = Binder.clearCallingIdentity(); |
| 2852 | try { |
| 2853 | if (phone != null) { |
| 2854 | return phone.getDataActivationState(); |
| 2855 | } else { |
| 2856 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2857 | } |
| 2858 | } finally { |
| 2859 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2864 | * Returns the unread count of voicemails for a subId |
| 2865 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2866 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2867 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2868 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2869 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2870 | return 0; |
| 2871 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 | final long identity = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | final Phone phone = getPhone(subId); |
| 2875 | if (phone != null) { |
| 2876 | return phone.getVoiceMessageCount(); |
| 2877 | } else { |
| 2878 | return 0; |
| 2879 | } |
| 2880 | } finally { |
| 2881 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2882 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2886 | * returns true, if the device is in a state where both voice and data |
| 2887 | * are supported simultaneously. This can change based on location or network condition. |
| 2888 | */ |
| 2889 | @Override |
| 2890 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2891 | final long identity = Binder.clearCallingIdentity(); |
| 2892 | try { |
| 2893 | final Phone phone = getPhone(subId); |
| 2894 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2895 | } finally { |
| 2896 | Binder.restoreCallingIdentity(identity); |
| 2897 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2901 | * Send the dialer code if called from the current default dialer or the caller has |
| 2902 | * carrier privilege. |
| 2903 | * @param inputCode The dialer code to send |
| 2904 | */ |
| 2905 | @Override |
| 2906 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2907 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2908 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2909 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 2910 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2911 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2912 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2913 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2914 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2915 | |
| 2916 | final long identity = Binder.clearCallingIdentity(); |
| 2917 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2918 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2919 | } finally { |
| 2920 | Binder.restoreCallingIdentity(identity); |
| 2921 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2922 | } |
| 2923 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2924 | @Override |
| 2925 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2926 | if (!isActiveSubscription(subId)) { |
| 2927 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2928 | } |
| 2929 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2930 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2931 | } |
| 2932 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2933 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2934 | public boolean isInEmergencySmsMode() { |
| 2935 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2936 | final long identity = Binder.clearCallingIdentity(); |
| 2937 | try { |
| 2938 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2939 | if (phone.isInEmergencySmsMode()) { |
| 2940 | return true; |
| 2941 | } |
| 2942 | } |
| 2943 | } finally { |
| 2944 | Binder.restoreCallingIdentity(identity); |
| 2945 | } |
| 2946 | return false; |
| 2947 | } |
| 2948 | |
| 2949 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2950 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2951 | throws RemoteException { |
| 2952 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 2953 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2954 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2955 | "IMS not available on device."); |
| 2956 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2957 | final long token = Binder.clearCallingIdentity(); |
| 2958 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2959 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2960 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2961 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2962 | } catch (ImsException e) { |
| 2963 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2964 | } finally { |
| 2965 | Binder.restoreCallingIdentity(token); |
| 2966 | } |
| 2967 | } |
| 2968 | |
| 2969 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2970 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2971 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2972 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2973 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2974 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2975 | final long token = Binder.clearCallingIdentity(); |
| 2976 | try { |
| 2977 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2978 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 2979 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2980 | } catch (ImsException e) { |
| 2981 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2982 | + "is inactive, ignoring unregister."); |
| 2983 | // If the subscription is no longer active, just return, since the callback |
| 2984 | // will already have been removed internally. |
| 2985 | } finally { |
| 2986 | Binder.restoreCallingIdentity(token); |
| 2987 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 2990 | /** |
| 2991 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 2992 | */ |
| 2993 | @Override |
| 2994 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 2995 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 2996 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2997 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2998 | "IMS not available on device."); |
| 2999 | } |
| 3000 | final long token = Binder.clearCallingIdentity(); |
| 3001 | try { |
| 3002 | Phone phone = getPhone(subId); |
| 3003 | if (phone == null) { |
| 3004 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3005 | + subId + "'"); |
| 3006 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3007 | } |
| 3008 | phone.getImsRegistrationState(regState -> { |
| 3009 | try { |
| 3010 | consumer.accept((regState == null) |
| 3011 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3012 | } catch (RemoteException e) { |
| 3013 | // Ignore if the remote process is no longer available to call back. |
| 3014 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3015 | } |
| 3016 | }); |
| 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(token); |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | /** |
| 3023 | * Get the transport type for the IMS service registration state. |
| 3024 | */ |
| 3025 | @Override |
| 3026 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
| 3027 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3028 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3029 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3030 | "IMS not available on device."); |
| 3031 | } |
| 3032 | final long token = Binder.clearCallingIdentity(); |
| 3033 | try { |
| 3034 | Phone phone = getPhone(subId); |
| 3035 | if (phone == null) { |
| 3036 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3037 | + subId + "'"); |
| 3038 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3039 | } |
| 3040 | phone.getImsRegistrationTech(regTech -> { |
| 3041 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3042 | int regTechConverted = (regTech == null) |
| 3043 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3044 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3045 | regTechConverted); |
| 3046 | try { |
| 3047 | consumer.accept(regTechConverted); |
| 3048 | } catch (RemoteException e) { |
| 3049 | // Ignore if the remote process is no longer available to call back. |
| 3050 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3051 | } |
| 3052 | }); |
| 3053 | } finally { |
| 3054 | Binder.restoreCallingIdentity(token); |
| 3055 | } |
| 3056 | } |
| 3057 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3058 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3059 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3060 | throws RemoteException { |
| 3061 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3062 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3063 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3064 | "IMS not available on device."); |
| 3065 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3066 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3067 | final long token = Binder.clearCallingIdentity(); |
| 3068 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3069 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3070 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3071 | } catch (ImsException e) { |
| 3072 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3073 | } finally { |
| 3074 | Binder.restoreCallingIdentity(token); |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3079 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 3080 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3081 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3082 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3083 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3084 | |
| 3085 | final long token = Binder.clearCallingIdentity(); |
| 3086 | try { |
| 3087 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3088 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3089 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3090 | } catch (ImsException e) { |
| 3091 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3092 | + "is inactive, ignoring unregister."); |
| 3093 | // If the subscription is no longer active, just return, since the callback |
| 3094 | // will already have been removed internally. |
| 3095 | } finally { |
| 3096 | Binder.restoreCallingIdentity(token); |
| 3097 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3101 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3102 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3103 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3104 | final long token = Binder.clearCallingIdentity(); |
| 3105 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3106 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3107 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3108 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3109 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3110 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3111 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3112 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3113 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3114 | } finally { |
| 3115 | Binder.restoreCallingIdentity(token); |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3120 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3121 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3122 | final long token = Binder.clearCallingIdentity(); |
| 3123 | try { |
| 3124 | Phone phone = getPhone(subId); |
| 3125 | if (phone == null) return false; |
| 3126 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3127 | } finally { |
| 3128 | Binder.restoreCallingIdentity(token); |
| 3129 | } |
| 3130 | } |
| 3131 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3132 | /** |
| 3133 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3134 | * subscription. |
| 3135 | * @param subId The subscription to use to check the configuration. |
| 3136 | * @param callback The callback that will be used to send the result. |
| 3137 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3138 | * @param transportType The transport type of the MmTelFeature capability. |
| 3139 | */ |
| 3140 | @Override |
| 3141 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3142 | int transportType) { |
| 3143 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3144 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3145 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3146 | "IMS not available on device."); |
| 3147 | } |
| 3148 | final long token = Binder.clearCallingIdentity(); |
| 3149 | try { |
| 3150 | int slotId = getSlotIndex(subId); |
| 3151 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3152 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3153 | + subId + "'"); |
| 3154 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3155 | } |
| 3156 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3157 | transportType, aBoolean -> { |
| 3158 | try { |
| 3159 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3160 | } catch (RemoteException e) { |
| 3161 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3162 | + "running. Ignore"); |
| 3163 | } |
| 3164 | }); |
| 3165 | } finally { |
| 3166 | Binder.restoreCallingIdentity(token); |
| 3167 | } |
| 3168 | } |
| 3169 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3170 | @Override |
| 3171 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 3172 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 3173 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3174 | final long token = Binder.clearCallingIdentity(); |
| 3175 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3176 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3177 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3178 | } catch (ImsException e) { |
| 3179 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3180 | } finally { |
| 3181 | Binder.restoreCallingIdentity(token); |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3186 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3187 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3188 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3189 | final long identity = Binder.clearCallingIdentity(); |
| 3190 | try { |
| 3191 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3192 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3193 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3194 | } catch (ImsException e) { |
| 3195 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3196 | } finally { |
| 3197 | Binder.restoreCallingIdentity(identity); |
| 3198 | } |
| 3199 | } |
| 3200 | |
| 3201 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3202 | public boolean isVtSettingEnabled(int subId) { |
| 3203 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3204 | final long identity = Binder.clearCallingIdentity(); |
| 3205 | try { |
| 3206 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3207 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3208 | } catch (ImsException e) { |
| 3209 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3210 | } finally { |
| 3211 | Binder.restoreCallingIdentity(identity); |
| 3212 | } |
| 3213 | } |
| 3214 | |
| 3215 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3216 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3217 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3218 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3219 | final long identity = Binder.clearCallingIdentity(); |
| 3220 | try { |
| 3221 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3222 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3223 | } catch (ImsException e) { |
| 3224 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3225 | } finally { |
| 3226 | Binder.restoreCallingIdentity(identity); |
| 3227 | } |
| 3228 | } |
| 3229 | |
| 3230 | @Override |
| 3231 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3232 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3233 | final long identity = Binder.clearCallingIdentity(); |
| 3234 | try { |
| 3235 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3236 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3237 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3238 | } catch (ImsException e) { |
| 3239 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3240 | } finally { |
| 3241 | Binder.restoreCallingIdentity(identity); |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3246 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3248 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3249 | final long identity = Binder.clearCallingIdentity(); |
| 3250 | try { |
| 3251 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3252 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3253 | } catch (ImsException e) { |
| 3254 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3255 | } finally { |
| 3256 | Binder.restoreCallingIdentity(identity); |
| 3257 | } |
| 3258 | } |
| 3259 | |
| 3260 | @Override |
| 3261 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3262 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3263 | final long identity = Binder.clearCallingIdentity(); |
| 3264 | try { |
| 3265 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3266 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3267 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3268 | } catch (ImsException e) { |
| 3269 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3270 | } finally { |
| 3271 | Binder.restoreCallingIdentity(identity); |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3276 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3277 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3278 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3279 | final long identity = Binder.clearCallingIdentity(); |
| 3280 | try { |
| 3281 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3282 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3283 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3284 | } catch (ImsException e) { |
| 3285 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3286 | } finally { |
| 3287 | Binder.restoreCallingIdentity(identity); |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | @Override |
| 3292 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3294 | "setVoWiFiNonPersistent"); |
| 3295 | final long identity = Binder.clearCallingIdentity(); |
| 3296 | try { |
| 3297 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3298 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3299 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3300 | } catch (ImsException e) { |
| 3301 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(identity); |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | @Override |
| 3308 | public int getVoWiFiModeSetting(int subId) { |
| 3309 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3310 | final long identity = Binder.clearCallingIdentity(); |
| 3311 | try { |
| 3312 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3313 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3314 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3315 | } catch (ImsException e) { |
| 3316 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3317 | } finally { |
| 3318 | Binder.restoreCallingIdentity(identity); |
| 3319 | } |
| 3320 | } |
| 3321 | |
| 3322 | @Override |
| 3323 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3324 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3325 | "setVoWiFiModeSetting"); |
| 3326 | final long identity = Binder.clearCallingIdentity(); |
| 3327 | try { |
| 3328 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3329 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3330 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3331 | } catch (ImsException e) { |
| 3332 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3333 | } finally { |
| 3334 | Binder.restoreCallingIdentity(identity); |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | @Override |
| 3339 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3340 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3341 | final long identity = Binder.clearCallingIdentity(); |
| 3342 | try { |
| 3343 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3344 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3345 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3346 | } catch (ImsException e) { |
| 3347 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3348 | } finally { |
| 3349 | Binder.restoreCallingIdentity(identity); |
| 3350 | } |
| 3351 | } |
| 3352 | |
| 3353 | @Override |
| 3354 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3356 | "setVoWiFiRoamingModeSetting"); |
| 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
| 3359 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3360 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3361 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3362 | } catch (ImsException e) { |
| 3363 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3364 | } finally { |
| 3365 | Binder.restoreCallingIdentity(identity); |
| 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | @Override |
| 3370 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3371 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3372 | "setRttCapabilityEnabled"); |
| 3373 | final long identity = Binder.clearCallingIdentity(); |
| 3374 | try { |
| 3375 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3376 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3377 | } catch (ImsException e) { |
| 3378 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3379 | } finally { |
| 3380 | Binder.restoreCallingIdentity(identity); |
| 3381 | } |
| 3382 | } |
| 3383 | |
| 3384 | @Override |
| 3385 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3386 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3387 | final long identity = Binder.clearCallingIdentity(); |
| 3388 | try { |
| 3389 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3390 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3391 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3392 | } catch (ImsException e) { |
| 3393 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3394 | } finally { |
| 3395 | Binder.restoreCallingIdentity(identity); |
| 3396 | } |
| 3397 | } |
| 3398 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3399 | @Override |
| 3400 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3401 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3402 | final long identity = Binder.clearCallingIdentity(); |
| 3403 | try { |
| 3404 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3405 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3406 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3407 | } catch (ImsException e) { |
| 3408 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3409 | } finally { |
| 3410 | Binder.restoreCallingIdentity(identity); |
| 3411 | } |
| 3412 | } |
| 3413 | |
| 3414 | @Override |
| 3415 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3416 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3417 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3418 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3419 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3420 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3421 | try { |
| 3422 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3423 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3424 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3425 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3426 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3427 | + "is inactive, ignoring unregister."); |
| 3428 | // If the subscription is no longer active, just return, since the callback will already |
| 3429 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3430 | } finally { |
| 3431 | Binder.restoreCallingIdentity(identity); |
| 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3436 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3437 | boolean isProvisioned) { |
| 3438 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3439 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3440 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3441 | } |
| 3442 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3443 | "setProvisioningStatusForCapability"); |
| 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
| 3446 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3447 | Phone phone = getPhone(subId); |
| 3448 | if (phone == null) { |
| 3449 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3450 | + subId); |
| 3451 | return; |
| 3452 | } |
| 3453 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3454 | return; |
| 3455 | } |
| 3456 | |
| 3457 | // this capability requires provisioning, route to the correct API. |
| 3458 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3459 | switch (capability) { |
| 3460 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3461 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3462 | ims.setVolteProvisioned(isProvisioned); |
| 3463 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3464 | ims.setWfcProvisioned(isProvisioned); |
| 3465 | } |
| 3466 | break; |
| 3467 | } |
| 3468 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3469 | // There is currently no difference in VT provisioning type. |
| 3470 | ims.setVtProvisioned(isProvisioned); |
| 3471 | break; |
| 3472 | } |
| 3473 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3474 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3475 | // change the capability of the feature instead if needed. |
| 3476 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3477 | == isProvisioned) { |
| 3478 | // No change in provisioning. |
| 3479 | return; |
| 3480 | } |
| 3481 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3482 | try { |
| 3483 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3484 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3485 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3486 | + ", Exception" + e.getMessage()); |
| 3487 | } |
| 3488 | break; |
| 3489 | } |
| 3490 | default: { |
| 3491 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3492 | + capability + "', which does not require provisioning."); |
| 3493 | } |
| 3494 | } |
| 3495 | |
| 3496 | } finally { |
| 3497 | Binder.restoreCallingIdentity(identity); |
| 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | @Override |
| 3502 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3503 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3504 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3505 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3506 | } |
| 3507 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3508 | final long identity = Binder.clearCallingIdentity(); |
| 3509 | try { |
| 3510 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3511 | Phone phone = getPhone(subId); |
| 3512 | if (phone == null) { |
| 3513 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3514 | + subId); |
| 3515 | // We will fail with "true" as the provisioning status because this is the default |
| 3516 | // if we do not require provisioning. |
| 3517 | return true; |
| 3518 | } |
| 3519 | |
| 3520 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3521 | return true; |
| 3522 | } |
| 3523 | |
| 3524 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3525 | switch (capability) { |
| 3526 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3527 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3528 | return ims.isVolteProvisionedOnDevice(); |
| 3529 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3530 | return ims.isWfcProvisionedOnDevice(); |
| 3531 | } |
| 3532 | // This should never happen, since we are checking tech above to make sure it |
| 3533 | // is either LTE or IWLAN. |
| 3534 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3535 | + "capability."); |
| 3536 | } |
| 3537 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3538 | // There is currently no difference in VT provisioning type. |
| 3539 | return ims.isVtProvisionedOnDevice(); |
| 3540 | } |
| 3541 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3542 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3543 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3544 | } |
| 3545 | default: { |
| 3546 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3547 | + capability + "', which does not require provisioning."); |
| 3548 | } |
| 3549 | } |
| 3550 | |
| 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | @Override |
| 3557 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3558 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3559 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3560 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3561 | } |
| 3562 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3563 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3564 | return (provisionedBits & capability) > 0; |
| 3565 | } |
| 3566 | |
| 3567 | @Override |
| 3568 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3569 | boolean isProvisioned) { |
| 3570 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3571 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3572 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3573 | } |
| 3574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3575 | "setProvisioningStatusForCapability"); |
| 3576 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3577 | // If the current provisioning status for capability already matches isProvisioned, |
| 3578 | // do nothing. |
| 3579 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3580 | return; |
| 3581 | } |
| 3582 | if (isProvisioned) { |
| 3583 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3584 | } else { |
| 3585 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3591 | * technology. The bitfield should mirror the bitfield defined by |
| 3592 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3593 | */ |
| 3594 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3595 | String key = getMmTelProvisioningKey(subId, tech); |
| 3596 | // Default is no capabilities are provisioned. |
| 3597 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3598 | } |
| 3599 | |
| 3600 | /** |
| 3601 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3602 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3603 | * technology specified. |
| 3604 | * |
| 3605 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3606 | */ |
| 3607 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3608 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3609 | String key = getMmTelProvisioningKey(subId, tech); |
| 3610 | editor.putInt(key, newField); |
| 3611 | editor.commit(); |
| 3612 | } |
| 3613 | |
| 3614 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3615 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3616 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3617 | } |
| 3618 | |
| 3619 | /** |
| 3620 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3621 | * carrier associated with the subscription id. |
| 3622 | */ |
| 3623 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3624 | int capability) { |
| 3625 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3626 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3627 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3628 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3629 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3630 | false); |
| 3631 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3632 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3633 | |
| 3634 | // First check to make sure that the capability requires provisioning. |
| 3635 | switch (capability) { |
| 3636 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3637 | // intentional fallthrough |
| 3638 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3639 | if (requireVoiceVtProvisioning) { |
| 3640 | // Voice and Video requires provisioning |
| 3641 | return true; |
| 3642 | } |
| 3643 | break; |
| 3644 | } |
| 3645 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3646 | if (requireUtProvisioning) { |
| 3647 | // UT requires provisioning |
| 3648 | return true; |
| 3649 | } |
| 3650 | break; |
| 3651 | } |
| 3652 | } |
| 3653 | return false; |
| 3654 | } |
| 3655 | |
| 3656 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3657 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3658 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3659 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3660 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3661 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3662 | final long identity = Binder.clearCallingIdentity(); |
| 3663 | try { |
| 3664 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3665 | int slotId = getSlotIndex(subId); |
| 3666 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3667 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3668 | + subId + "' for key:" + key); |
| 3669 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3670 | } |
| 3671 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3672 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3673 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3674 | + subId + "' for key:" + key); |
| 3675 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3676 | } finally { |
| 3677 | Binder.restoreCallingIdentity(identity); |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | @Override |
| 3682 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3683 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3684 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3685 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3686 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
| 3689 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3690 | int slotId = getSlotIndex(subId); |
| 3691 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3692 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3693 | + subId + "' for key:" + key); |
| 3694 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3695 | } |
| 3696 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3697 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3698 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3699 | + subId + "' for key:" + key); |
| 3700 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3701 | } finally { |
| 3702 | Binder.restoreCallingIdentity(identity); |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | @Override |
| 3707 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3708 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3709 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3710 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3712 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3716 | int slotId = getSlotIndex(subId); |
| 3717 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3718 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3719 | + subId + "' for key:" + key); |
| 3720 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3721 | } |
| 3722 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3723 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3724 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3725 | + "' for key:" + key); |
| 3726 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3727 | } finally { |
| 3728 | Binder.restoreCallingIdentity(identity); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | @Override |
| 3733 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3734 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3735 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3736 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3738 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3739 | final long identity = Binder.clearCallingIdentity(); |
| 3740 | try { |
| 3741 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3742 | int slotId = getSlotIndex(subId); |
| 3743 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3744 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3745 | + subId + "' for key:" + key); |
| 3746 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3747 | } |
| 3748 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3749 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3750 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3751 | + "' for key:" + key); |
| 3752 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3753 | } finally { |
| 3754 | Binder.restoreCallingIdentity(identity); |
| 3755 | } |
| 3756 | } |
| 3757 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3758 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3759 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3760 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3761 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3762 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | } |
| 3764 | return slotId; |
| 3765 | } |
| 3766 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3767 | private int getSlotIndex(int subId) { |
| 3768 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3769 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3770 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3771 | } |
| 3772 | return slotId; |
| 3773 | } |
| 3774 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3775 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3776 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3777 | */ |
| 3778 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3779 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3780 | final int targetSdk = getTargetSdk(callingPackage); |
| 3781 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| 3782 | return getDataNetworkTypeForSubscriber(subId, callingPackage); |
| 3783 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3784 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3785 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3786 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3787 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3788 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3789 | final long identity = Binder.clearCallingIdentity(); |
| 3790 | try { |
| 3791 | final Phone phone = getPhone(subId); |
| 3792 | if (phone != null) { |
| 3793 | return phone.getServiceState().getDataNetworkType(); |
| 3794 | } else { |
| 3795 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3796 | } |
| 3797 | } finally { |
| 3798 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3799 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | /** |
| 3803 | * Returns the data network type |
| 3804 | */ |
| 3805 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3806 | public int getDataNetworkType(String callingPackage) { |
| 3807 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | /** |
| 3811 | * Returns the data network type for a subId |
| 3812 | */ |
| 3813 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3814 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3815 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3816 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3817 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3818 | } |
| 3819 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3820 | final long identity = Binder.clearCallingIdentity(); |
| 3821 | try { |
| 3822 | final Phone phone = getPhone(subId); |
| 3823 | if (phone != null) { |
| 3824 | return phone.getServiceState().getDataNetworkType(); |
| 3825 | } else { |
| 3826 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3827 | } |
| 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3830 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3834 | * Returns the Voice network type for a subId |
| 3835 | */ |
| 3836 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3837 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3838 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3839 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3840 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3841 | } |
| 3842 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3843 | final long identity = Binder.clearCallingIdentity(); |
| 3844 | try { |
| 3845 | final Phone phone = getPhone(subId); |
| 3846 | if (phone != null) { |
| 3847 | return phone.getServiceState().getVoiceNetworkType(); |
| 3848 | } else { |
| 3849 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3850 | } |
| 3851 | } finally { |
| 3852 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3853 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | /** |
| 3857 | * @return true if a ICC card is present |
| 3858 | */ |
| 3859 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3860 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3861 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3862 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3866 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3867 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3868 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3869 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3870 | final long identity = Binder.clearCallingIdentity(); |
| 3871 | try { |
| 3872 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3873 | if (phone != null) { |
| 3874 | return phone.getIccCard().hasIccCard(); |
| 3875 | } else { |
| 3876 | return false; |
| 3877 | } |
| 3878 | } finally { |
| 3879 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3880 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | /** |
| 3884 | * Return if the current radio is LTE on CDMA. This |
| 3885 | * is a tri-state return value as for a period of time |
| 3886 | * the mode may be unknown. |
| 3887 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3888 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3889 | * @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] | 3890 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3891 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3892 | @Override |
| 3893 | public int getLteOnCdmaMode(String callingPackage) { |
| 3894 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3897 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3898 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3899 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3900 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3901 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3902 | } |
| 3903 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3904 | final long identity = Binder.clearCallingIdentity(); |
| 3905 | try { |
| 3906 | final Phone phone = getPhone(subId); |
| 3907 | if (phone == null) { |
| 3908 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3909 | } else { |
| 3910 | return phone.getLteOnCdmaMode(); |
| 3911 | } |
| 3912 | } finally { |
| 3913 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3914 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3917 | /** |
| 3918 | * {@hide} |
| 3919 | * Returns Default subId, 0 in the case of single standby. |
| 3920 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3921 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3922 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3925 | private int getSlotForDefaultSubscription() { |
| 3926 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3927 | } |
| 3928 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3929 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3930 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3931 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3932 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3933 | private boolean isActiveSubscription(int subId) { |
| 3934 | return mSubscriptionController.isActiveSubId(subId); |
| 3935 | } |
| 3936 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3937 | /** |
| 3938 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3939 | */ |
| 3940 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3941 | final long identity = Binder.clearCallingIdentity(); |
| 3942 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3943 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3944 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3945 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3946 | } finally { |
| 3947 | Binder.restoreCallingIdentity(identity); |
| 3948 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3949 | } |
| 3950 | |
| 3951 | /** |
| 3952 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3953 | */ |
| 3954 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | final long identity = Binder.clearCallingIdentity(); |
| 3956 | try { |
| 3957 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3958 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3959 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(identity); |
| 3962 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3963 | } |
| 3964 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3965 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3966 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3967 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3968 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3969 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3970 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3971 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3972 | if (phoneId == -1) { |
| 3973 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3974 | + " does not correspond to an active phone"); |
| 3975 | } |
| 3976 | return PhoneFactory.getPhone(phoneId); |
| 3977 | } |
| 3978 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3979 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3980 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3981 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3983 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3984 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3985 | if (DBG) { |
| 3986 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3987 | } |
| 3988 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3989 | p2); |
| 3990 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3991 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3992 | |
| 3993 | @Override |
| 3994 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3995 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3996 | enforceModifyPermission(); |
| 3997 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3998 | if (DBG) { |
| 3999 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4000 | } |
| 4001 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4002 | callingPackage, aid, p2); |
| 4003 | } |
| 4004 | |
| 4005 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4006 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4007 | final long identity = Binder.clearCallingIdentity(); |
| 4008 | try { |
| 4009 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4010 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4011 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4012 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4013 | if (bestComponent == null |
| 4014 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4015 | loge("The calling package is not allowed to access ISD-R."); |
| 4016 | throw new SecurityException( |
| 4017 | "The calling package is not allowed to access ISD-R."); |
| 4018 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4019 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4020 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4022 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4023 | null /* workSource */); |
| 4024 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4025 | return response; |
| 4026 | } finally { |
| 4027 | Binder.restoreCallingIdentity(identity); |
| 4028 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4032 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4034 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4035 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4036 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4037 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4038 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4039 | @Override |
| 4040 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4041 | enforceModifyPermission(); |
| 4042 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4043 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4044 | channel); |
| 4045 | } |
| 4046 | |
| 4047 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | final long identity = Binder.clearCallingIdentity(); |
| 4049 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | if (channel < 0) { |
| 4051 | return false; |
| 4052 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4053 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4054 | null /* workSource */); |
| 4055 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4056 | return success; |
| 4057 | } finally { |
| 4058 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4059 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4063 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4064 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4065 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4066 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4067 | if (DBG) { |
| 4068 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4069 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4070 | + p3 + " data=" + data); |
| 4071 | } |
| 4072 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4073 | command, p1, p2, p3, data); |
| 4074 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4075 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4076 | @Override |
| 4077 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4078 | int command, int p1, int p2, int p3, String data) { |
| 4079 | enforceModifyPermission(); |
| 4080 | if (DBG) { |
| 4081 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4082 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4083 | + p3 + " data=" + data); |
| 4084 | } |
| 4085 | return iccTransmitApduLogicalChannelWithPermission( |
| 4086 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4087 | data); |
| 4088 | } |
| 4089 | |
| 4090 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4091 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | final long identity = Binder.clearCallingIdentity(); |
| 4093 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4094 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4095 | return ""; |
| 4096 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4098 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4099 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4100 | null /* workSource */); |
| 4101 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4102 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4103 | // Append the returned status code to the end of the response payload. |
| 4104 | String s = Integer.toHexString( |
| 4105 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4106 | if (response.payload != null) { |
| 4107 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4108 | } |
| 4109 | return s; |
| 4110 | } finally { |
| 4111 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4112 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4113 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4114 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4115 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4116 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4117 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4118 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4119 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4120 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4121 | if (DBG) { |
| 4122 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4123 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4124 | } |
| 4125 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4126 | cla, command, p1, p2, p3, data); |
| 4127 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4128 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4129 | @Override |
| 4130 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4131 | int command, int p1, int p2, int p3, String data) { |
| 4132 | enforceModifyPermission(); |
| 4133 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4134 | if (DBG) { |
| 4135 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4136 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4137 | + " data=" + data); |
| 4138 | } |
| 4139 | |
| 4140 | return iccTransmitApduBasicChannelWithPermission( |
| 4141 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4142 | p2, p3, data); |
| 4143 | } |
| 4144 | |
| 4145 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4146 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4147 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | final long identity = Binder.clearCallingIdentity(); |
| 4149 | try { |
| 4150 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4151 | && TextUtils.equals(ISDR_AID, data)) { |
| 4152 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4153 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4154 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4155 | if (bestComponent == null |
| 4156 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4157 | loge("The calling package is not allowed to select ISD-R."); |
| 4158 | throw new SecurityException( |
| 4159 | "The calling package is not allowed to select ISD-R."); |
| 4160 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4161 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4163 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4164 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4165 | null /* workSource */); |
| 4166 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4167 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4168 | // Append the returned status code to the end of the response payload. |
| 4169 | String s = Integer.toHexString( |
| 4170 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4171 | if (response.payload != null) { |
| 4172 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4173 | } |
| 4174 | return s; |
| 4175 | } finally { |
| 4176 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4177 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4181 | 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] | 4182 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4183 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4184 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4185 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4186 | final long identity = Binder.clearCallingIdentity(); |
| 4187 | try { |
| 4188 | if (DBG) { |
| 4189 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4190 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4191 | } |
| 4192 | |
| 4193 | IccIoResult response = |
| 4194 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4195 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4196 | subId); |
| 4197 | |
| 4198 | if (DBG) { |
| 4199 | log("Exchange SIM_IO [R]" + response); |
| 4200 | } |
| 4201 | |
| 4202 | byte[] result = null; |
| 4203 | int length = 2; |
| 4204 | if (response.payload != null) { |
| 4205 | length = 2 + response.payload.length; |
| 4206 | result = new byte[length]; |
| 4207 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4208 | } else { |
| 4209 | result = new byte[length]; |
| 4210 | } |
| 4211 | |
| 4212 | result[length - 1] = (byte) response.sw2; |
| 4213 | result[length - 2] = (byte) response.sw1; |
| 4214 | return result; |
| 4215 | } finally { |
| 4216 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4217 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4220 | /** |
| 4221 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4222 | * on a particular subscription |
| 4223 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4224 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4225 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4226 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4227 | return null; |
| 4228 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4229 | |
| 4230 | final long identity = Binder.clearCallingIdentity(); |
| 4231 | try { |
| 4232 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4233 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4234 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4235 | return null; |
| 4236 | } |
| 4237 | Object response = sendRequest( |
| 4238 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4239 | if (response instanceof String[]) { |
| 4240 | return (String[]) response; |
| 4241 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4242 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4243 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4244 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4247 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4248 | } |
| 4249 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4250 | /** |
| 4251 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4252 | * subscription. |
| 4253 | * |
| 4254 | * @param subId the id of the subscription. |
| 4255 | * @param appType the uicc app type, must be USIM or SIM. |
| 4256 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4257 | * @param callingPackage the op Package name. |
| 4258 | * @return number of fplmns that is successfully written to the SIM. |
| 4259 | */ |
| 4260 | public int setForbiddenPlmns( |
| 4261 | int subId, int appType, List<String> fplmns, String callingPackage) { |
| 4262 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4263 | mApp, subId, callingPackage, "setForbiddenPlmns")) { |
| 4264 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4265 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4266 | } |
| 4267 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4268 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4269 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4270 | } |
| 4271 | if (fplmns == null) { |
| 4272 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4273 | } |
| 4274 | for (String fplmn : fplmns) { |
| 4275 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4276 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4277 | } |
| 4278 | } |
| 4279 | final long identity = Binder.clearCallingIdentity(); |
| 4280 | try { |
| 4281 | Object response = sendRequest( |
| 4282 | CMD_SET_FORBIDDEN_PLMNS, |
| 4283 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4284 | subId); |
| 4285 | return (int) response; |
| 4286 | } finally { |
| 4287 | Binder.restoreCallingIdentity(identity); |
| 4288 | } |
| 4289 | } |
| 4290 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4291 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4292 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4294 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4295 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4296 | final long identity = Binder.clearCallingIdentity(); |
| 4297 | try { |
| 4298 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4299 | if (response.payload == null) { |
| 4300 | return ""; |
| 4301 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4302 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4303 | // Append the returned status code to the end of the response payload. |
| 4304 | String s = Integer.toHexString( |
| 4305 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4306 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4307 | return s; |
| 4308 | } finally { |
| 4309 | Binder.restoreCallingIdentity(identity); |
| 4310 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4311 | } |
| 4312 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4313 | /** |
| 4314 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4315 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4316 | * |
| 4317 | * @param itemID the ID of the item to read |
| 4318 | * @return the NV item as a String, or null on error. |
| 4319 | */ |
| 4320 | @Override |
| 4321 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4322 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4324 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4325 | |
| 4326 | final long identity = Binder.clearCallingIdentity(); |
| 4327 | try { |
| 4328 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4329 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4330 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4331 | return value; |
| 4332 | } finally { |
| 4333 | Binder.restoreCallingIdentity(identity); |
| 4334 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | /** |
| 4338 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4339 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4340 | * |
| 4341 | * @param itemID the ID of the item to read |
| 4342 | * @param itemValue the value to write, as a String |
| 4343 | * @return true on success; false on any failure |
| 4344 | */ |
| 4345 | @Override |
| 4346 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4347 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4348 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4349 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4350 | |
| 4351 | final long identity = Binder.clearCallingIdentity(); |
| 4352 | try { |
| 4353 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4354 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4355 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4356 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4357 | return success; |
| 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
| 4360 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | /** |
| 4364 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4365 | * Used for device configuration by some CDMA operators. |
| 4366 | * |
| 4367 | * @param preferredRoamingList byte array containing the new PRL |
| 4368 | * @return true on success; false on any failure |
| 4369 | */ |
| 4370 | @Override |
| 4371 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4373 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4374 | |
| 4375 | final long identity = Binder.clearCallingIdentity(); |
| 4376 | try { |
| 4377 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4378 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4379 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4380 | return success; |
| 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(identity); |
| 4383 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4387 | * 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] | 4388 | * Used for device configuration by some CDMA operators. |
| 4389 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4390 | * @param slotIndex - device slot. |
| 4391 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4392 | * @return true on success; false on any failure |
| 4393 | */ |
| 4394 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4395 | public boolean resetModemConfig(int slotIndex) { |
| 4396 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4397 | if (phone != null) { |
| 4398 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4399 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4400 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4401 | final long identity = Binder.clearCallingIdentity(); |
| 4402 | try { |
| 4403 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4404 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4405 | return success; |
| 4406 | } finally { |
| 4407 | Binder.restoreCallingIdentity(identity); |
| 4408 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4409 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4410 | return false; |
| 4411 | } |
| 4412 | |
| 4413 | /** |
| 4414 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4415 | * |
| 4416 | * @param slotIndex - device slot. |
| 4417 | * |
| 4418 | * @return true on success; false on any failure |
| 4419 | */ |
| 4420 | @Override |
| 4421 | public boolean rebootModem(int slotIndex) { |
| 4422 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4423 | if (phone != null) { |
| 4424 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4425 | mApp, phone.getSubId(), "rebootModem"); |
| 4426 | |
| 4427 | final long identity = Binder.clearCallingIdentity(); |
| 4428 | try { |
| 4429 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4430 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4431 | return success; |
| 4432 | } finally { |
| 4433 | Binder.restoreCallingIdentity(identity); |
| 4434 | } |
| 4435 | } |
| 4436 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4437 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4438 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4439 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4440 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4441 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4442 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4443 | return new String[0]; |
| 4444 | } |
| 4445 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4446 | final long identity = Binder.clearCallingIdentity(); |
| 4447 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4448 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4449 | } finally { |
| 4450 | Binder.restoreCallingIdentity(identity); |
| 4451 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4452 | } |
| 4453 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4454 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4455 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4456 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4457 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4458 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4459 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4460 | |
| 4461 | final long identity = Binder.clearCallingIdentity(); |
| 4462 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4463 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4464 | // may happen if the device does not support IMS. |
| 4465 | return; |
| 4466 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4467 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4468 | } finally { |
| 4469 | Binder.restoreCallingIdentity(identity); |
| 4470 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4474 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4475 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4476 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4477 | public void disableIms(int slotId) { |
| 4478 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4479 | |
| 4480 | final long identity = Binder.clearCallingIdentity(); |
| 4481 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4482 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4483 | // may happen if the device does not support IMS. |
| 4484 | return; |
| 4485 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4486 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
| 4489 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | /** |
| 4493 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4494 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4495 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4496 | */ |
| 4497 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4498 | IImsServiceFeatureCallback callback) { |
| 4499 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4500 | |
| 4501 | final long identity = Binder.clearCallingIdentity(); |
| 4502 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4503 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4504 | // may happen if the device does not support IMS. |
| 4505 | return null; |
| 4506 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4507 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
| 4510 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | /** |
| 4514 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4515 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4516 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4517 | * listener for feature updates. |
| 4518 | */ |
| 4519 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4520 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4521 | |
| 4522 | final long identity = Binder.clearCallingIdentity(); |
| 4523 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4524 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4525 | // may happen if the device does not support IMS. |
| 4526 | return null; |
| 4527 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4528 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4529 | } finally { |
| 4530 | Binder.restoreCallingIdentity(identity); |
| 4531 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4532 | } |
| 4533 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4534 | /** |
| 4535 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4536 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4537 | */ |
| 4538 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4539 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 | |
| 4541 | final long identity = Binder.clearCallingIdentity(); |
| 4542 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4543 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4544 | // may happen if the device does not support IMS. |
| 4545 | return null; |
| 4546 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4547 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4548 | } finally { |
| 4549 | Binder.restoreCallingIdentity(identity); |
| 4550 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4551 | } |
| 4552 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4553 | /** |
| 4554 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4555 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4556 | */ |
| 4557 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4558 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4559 | |
| 4560 | final long identity = Binder.clearCallingIdentity(); |
| 4561 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4562 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4563 | // may happen if the device does not support IMS. |
| 4564 | return null; |
| 4565 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4566 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4567 | } finally { |
| 4568 | Binder.restoreCallingIdentity(identity); |
| 4569 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4570 | } |
| 4571 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4572 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4573 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4574 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4575 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 4576 | * @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] | 4577 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4578 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 4579 | * @param packageName The name of the package that the current configuration will be replaced |
| 4580 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4581 | * @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] | 4582 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4583 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 4584 | int[] featureTypes, String packageName) { |
| 4585 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 4586 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4588 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4589 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4590 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4593 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4594 | // may happen if the device does not support IMS. |
| 4595 | return false; |
| 4596 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4597 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 4598 | for (int featureType : featureTypes) { |
| 4599 | featureConfig.put(featureType, packageName); |
| 4600 | } |
| 4601 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 4602 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4603 | } finally { |
| 4604 | Binder.restoreCallingIdentity(identity); |
| 4605 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4609 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4610 | * |
| 4611 | * @param slotId The slot that the ImsService is associated with. |
| 4612 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4613 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4614 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4615 | * @return the package name of the ImsService configuration. |
| 4616 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4617 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 4618 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4619 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4620 | TelephonyPermissions |
| 4621 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4622 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4623 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4624 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4625 | final long identity = Binder.clearCallingIdentity(); |
| 4626 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4627 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4628 | // may happen if the device does not support IMS. |
| 4629 | return ""; |
| 4630 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 4631 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4632 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 4633 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4634 | } finally { |
| 4635 | Binder.restoreCallingIdentity(identity); |
| 4636 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4637 | } |
| 4638 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4639 | /** |
| 4640 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4641 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4642 | * @param callback A callback with an integer containing the |
| 4643 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4644 | */ |
| 4645 | @Override |
| 4646 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4647 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4648 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4649 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4650 | "IMS not available on device."); |
| 4651 | } |
| 4652 | final long token = Binder.clearCallingIdentity(); |
| 4653 | try { |
| 4654 | int slotId = getSlotIndex(subId); |
| 4655 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4656 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4657 | + subId + "'"); |
| 4658 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4659 | } |
| 4660 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4661 | try { |
| 4662 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4663 | } catch (RemoteException e) { |
| 4664 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4665 | + "Ignore"); |
| 4666 | } |
| 4667 | }); |
| 4668 | } finally { |
| 4669 | Binder.restoreCallingIdentity(token); |
| 4670 | } |
| 4671 | } |
| 4672 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4673 | public void setImsRegistrationState(boolean registered) { |
| 4674 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4675 | |
| 4676 | final long identity = Binder.clearCallingIdentity(); |
| 4677 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4678 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4679 | } finally { |
| 4680 | Binder.restoreCallingIdentity(identity); |
| 4681 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4682 | } |
| 4683 | |
| 4684 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4685 | * Set the network selection mode to automatic. |
| 4686 | * |
| 4687 | */ |
| 4688 | @Override |
| 4689 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4691 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4692 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4693 | if (!isActiveSubscription(subId)) { |
| 4694 | return; |
| 4695 | } |
| 4696 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4697 | final long identity = Binder.clearCallingIdentity(); |
| 4698 | try { |
| 4699 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4700 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4701 | } finally { |
| 4702 | Binder.restoreCallingIdentity(identity); |
| 4703 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4704 | } |
| 4705 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4706 | /** |
| 4707 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4708 | * |
| 4709 | * @param subId the id of the subscription. |
| 4710 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4711 | * the operator to attach to. |
| 4712 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4713 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4714 | * normal network selection next time. |
| 4715 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4716 | */ |
| 4717 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4718 | public boolean setNetworkSelectionModeManual( |
| 4719 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4720 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4721 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4722 | |
| 4723 | if (!isActiveSubscription(subId)) { |
| 4724 | return false; |
| 4725 | } |
| 4726 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4727 | final long identity = Binder.clearCallingIdentity(); |
| 4728 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4729 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4730 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4731 | if (DBG) { |
| 4732 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4733 | + " operator: " + operatorInfo); |
| 4734 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4736 | } finally { |
| 4737 | Binder.restoreCallingIdentity(identity); |
| 4738 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | /** |
| 4742 | * Scans for available networks. |
| 4743 | */ |
| 4744 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4745 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4747 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4748 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4749 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4750 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4751 | .setCallingPackage(callingPackage) |
| 4752 | .setCallingPid(Binder.getCallingPid()) |
| 4753 | .setCallingUid(Binder.getCallingUid()) |
| 4754 | .setMethod("getCellNetworkScanResults") |
| 4755 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4756 | .build()); |
| 4757 | switch (locationResult) { |
| 4758 | case DENIED_HARD: |
| 4759 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4760 | case DENIED_SOFT: |
| 4761 | return null; |
| 4762 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4764 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4765 | try { |
| 4766 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4767 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4768 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | } finally { |
| 4770 | Binder.restoreCallingIdentity(identity); |
| 4771 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4772 | } |
| 4773 | |
| 4774 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4775 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4776 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4777 | * @param subId id of the subscription |
| 4778 | * @param request contains the radio access networks with bands/channels to scan |
| 4779 | * @param messenger callback messenger for scan results or errors |
| 4780 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4781 | * @return the id of the requested scan which can be used to stop the scan. |
| 4782 | */ |
| 4783 | @Override |
| 4784 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4785 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4786 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4787 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4788 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4789 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4790 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4791 | .setCallingPackage(callingPackage) |
| 4792 | .setCallingPid(Binder.getCallingPid()) |
| 4793 | .setCallingUid(Binder.getCallingUid()) |
| 4794 | .setMethod("requestNetworkScan") |
| 4795 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4796 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4797 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4798 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4799 | if (e != null) { |
| 4800 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4801 | throw e; |
| 4802 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4803 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4804 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4805 | } |
| 4806 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4807 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4808 | int callingUid = Binder.getCallingUid(); |
| 4809 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4810 | final long identity = Binder.clearCallingIdentity(); |
| 4811 | try { |
| 4812 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4813 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4814 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4815 | } finally { |
| 4816 | Binder.restoreCallingIdentity(identity); |
| 4817 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4818 | } |
| 4819 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4820 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4821 | NetworkScanRequest request, int subId) { |
| 4822 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4823 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4824 | boolean hasNetworkScanPermission = |
| 4825 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4826 | == PERMISSION_GRANTED; |
| 4827 | |
| 4828 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4829 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4830 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4834 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4835 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4836 | return new SecurityException("Specific channels must not be" |
| 4837 | + " scanned without location access."); |
| 4838 | } |
| 4839 | } |
| 4840 | } |
| 4841 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4842 | return null; |
| 4843 | } |
| 4844 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4845 | /** |
| 4846 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4847 | * |
| 4848 | * @param subId id of the subscription |
| 4849 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4850 | */ |
| 4851 | @Override |
| 4852 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4853 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4854 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4855 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4856 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4857 | final long identity = Binder.clearCallingIdentity(); |
| 4858 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4859 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | } finally { |
| 4861 | Binder.restoreCallingIdentity(identity); |
| 4862 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4866 | * Get the calculated preferred network type. |
| 4867 | * Used for debugging incorrect network type. |
| 4868 | * |
| 4869 | * @return the preferred network type, defined in RILConstants.java. |
| 4870 | */ |
| 4871 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4872 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4873 | final Phone defaultPhone = getDefaultPhone(); |
| 4874 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4875 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4876 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4877 | } |
| 4878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4879 | final long identity = Binder.clearCallingIdentity(); |
| 4880 | try { |
| 4881 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4882 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4883 | } finally { |
| 4884 | Binder.restoreCallingIdentity(identity); |
| 4885 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
| 4888 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4889 | * Get the preferred network type. |
| 4890 | * Used for device configuration by some CDMA operators. |
| 4891 | * |
| 4892 | * @return the preferred network type, defined in RILConstants.java. |
| 4893 | */ |
| 4894 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4895 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4896 | TelephonyPermissions |
| 4897 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4898 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4899 | |
| 4900 | final long identity = Binder.clearCallingIdentity(); |
| 4901 | try { |
| 4902 | if (DBG) log("getPreferredNetworkType"); |
| 4903 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4904 | int networkType = (result != null ? result[0] : -1); |
| 4905 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4906 | return networkType; |
| 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
| 4909 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | /** |
| 4913 | * Set the preferred network type. |
| 4914 | * Used for device configuration by some CDMA operators. |
| 4915 | * |
| 4916 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4917 | * @return true on success; false on any failure. |
| 4918 | */ |
| 4919 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4920 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4921 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4922 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4923 | |
| 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
| 4926 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4927 | Boolean success = (Boolean) sendRequest( |
| 4928 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4929 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4930 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4931 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4933 | } |
| 4934 | return success; |
| 4935 | } finally { |
| 4936 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4937 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4938 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4939 | |
| 4940 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4941 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4942 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4943 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4944 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4945 | * @hide |
| 4946 | */ |
| 4947 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 4948 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4949 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4951 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4952 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4953 | if (phone != null) { |
| 4954 | return phone.hasMatchedTetherApnSetting(); |
| 4955 | } else { |
| 4956 | return false; |
| 4957 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4958 | } finally { |
| 4959 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4960 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4964 | * Set mobile data enabled |
| 4965 | * Used by the user through settings etc to turn on/off mobile data |
| 4966 | * |
| 4967 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4968 | */ |
| 4969 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4970 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4971 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4972 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4973 | |
| 4974 | final long identity = Binder.clearCallingIdentity(); |
| 4975 | try { |
| 4976 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4977 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4978 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4979 | if (phone != null) { |
| 4980 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4981 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4982 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4983 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4984 | } |
| 4985 | } finally { |
| 4986 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4987 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4991 | * Get the user enabled state of Mobile Data. |
| 4992 | * |
| 4993 | * TODO: remove and use isUserDataEnabled. |
| 4994 | * This can't be removed now because some vendor codes |
| 4995 | * calls through ITelephony directly while they should |
| 4996 | * use TelephonyManager. |
| 4997 | * |
| 4998 | * @return true on enabled |
| 4999 | */ |
| 5000 | @Override |
| 5001 | public boolean getDataEnabled(int subId) { |
| 5002 | return isUserDataEnabled(subId); |
| 5003 | } |
| 5004 | |
| 5005 | /** |
| 5006 | * Get whether mobile data is enabled per user setting. |
| 5007 | * |
| 5008 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5009 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5010 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5011 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5012 | * |
| 5013 | * @return {@code true} if data is enabled else {@code false} |
| 5014 | */ |
| 5015 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5016 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5017 | try { |
| 5018 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5019 | null); |
| 5020 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5021 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5022 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5023 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5024 | |
| 5025 | final long identity = Binder.clearCallingIdentity(); |
| 5026 | try { |
| 5027 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5028 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5029 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5030 | if (phone != null) { |
| 5031 | boolean retVal = phone.isUserDataEnabled(); |
| 5032 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5033 | return retVal; |
| 5034 | } else { |
| 5035 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5036 | return false; |
| 5037 | } |
| 5038 | } finally { |
| 5039 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | /** |
| 5044 | * Get whether mobile data is enabled. |
| 5045 | * |
| 5046 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 5047 | * whether mobile data is actually enabled. |
| 5048 | * |
| 5049 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 5050 | * |
| 5051 | * @return {@code true} if data is enabled else {@code false} |
| 5052 | */ |
| 5053 | @Override |
| 5054 | public boolean isDataEnabled(int subId) { |
| 5055 | try { |
| 5056 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5057 | null); |
| 5058 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5059 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5060 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5061 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5062 | |
| 5063 | final long identity = Binder.clearCallingIdentity(); |
| 5064 | try { |
| 5065 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5066 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5067 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5068 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5069 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5070 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5071 | return retVal; |
| 5072 | } else { |
| 5073 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5074 | return false; |
| 5075 | } |
| 5076 | } finally { |
| 5077 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5078 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5079 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5080 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5081 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5082 | Phone phone) { |
| 5083 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5084 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5085 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5086 | || subController == null) return privilegeFromSim; |
| 5087 | |
| 5088 | int uid = Binder.getCallingUid(); |
| 5089 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5090 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5091 | |
| 5092 | final long identity = Binder.clearCallingIdentity(); |
| 5093 | try { |
| 5094 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5095 | SubscriptionManager subManager = (SubscriptionManager) |
| 5096 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5097 | for (String pkg : packages) { |
| 5098 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5099 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5100 | } |
| 5101 | } |
| 5102 | return privilegeFromSim; |
| 5103 | } finally { |
| 5104 | Binder.restoreCallingIdentity(identity); |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5109 | String pkgName) { |
| 5110 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5111 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5112 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5113 | || subController == null) return privilegeFromSim; |
| 5114 | |
| 5115 | final long identity = Binder.clearCallingIdentity(); |
| 5116 | try { |
| 5117 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5118 | SubscriptionManager subManager = (SubscriptionManager) |
| 5119 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5120 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5121 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5122 | } finally { |
| 5123 | Binder.restoreCallingIdentity(identity); |
| 5124 | } |
| 5125 | } |
| 5126 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5127 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5128 | public int getCarrierPrivilegeStatus(int subId) { |
| 5129 | final Phone phone = getPhone(subId); |
| 5130 | if (phone == null) { |
| 5131 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5132 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5133 | } |
| 5134 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5135 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5136 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5137 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5138 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5139 | |
| 5140 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5141 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5142 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5143 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5144 | |
| 5145 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5146 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 5147 | final Phone phone = getPhone(subId); |
| 5148 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5149 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5150 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5151 | } |
| 5152 | UiccProfile profile = |
| 5153 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5154 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5155 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5156 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5157 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5158 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5159 | profile.getCarrierPrivilegeStatusForUid( |
| 5160 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5164 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5165 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5166 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
| 5169 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5170 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5171 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5172 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5173 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5174 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5175 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5176 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5177 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | @Override |
| 5181 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5182 | if (TextUtils.isEmpty(pkgName)) |
| 5183 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5184 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5185 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5186 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5187 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5188 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5189 | continue; |
| 5190 | } |
| 5191 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5192 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5193 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5194 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5195 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5196 | break; |
| 5197 | } |
| 5198 | } |
| 5199 | |
| 5200 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5201 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5202 | |
| 5203 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5204 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5205 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5206 | loge("phoneId " + phoneId + " is not valid."); |
| 5207 | return null; |
| 5208 | } |
| 5209 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5210 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5211 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5212 | return null ; |
| 5213 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5214 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5215 | } |
| 5216 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5217 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5218 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5219 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5220 | List<String> privilegedPackages = new ArrayList<>(); |
| 5221 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5222 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5223 | // has UICC in that slot. |
| 5224 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5225 | if (card.hasCarrierPrivilegeRules()) { |
| 5226 | if (packages == null) { |
| 5227 | // Only check packages in user 0 for now |
| 5228 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5229 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5230 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5231 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5232 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5233 | } |
| 5234 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5235 | PackageInfo pkgInfo = packages.get(p); |
| 5236 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5237 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5238 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5239 | privilegedPackages.add(pkgInfo.packageName); |
| 5240 | } |
| 5241 | } |
| 5242 | } |
| 5243 | } |
| 5244 | return privilegedPackages; |
| 5245 | } |
| 5246 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5247 | @Override |
| 5248 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5249 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5250 | |
| 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5253 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5254 | try { |
| 5255 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5256 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5257 | } |
| 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5260 | } |
| 5261 | return privilegedPackages; |
| 5262 | } |
| 5263 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5264 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5265 | final Phone phone = getPhone(subId); |
| 5266 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5267 | if (card == null) { |
| 5268 | loge("getIccId: No UICC"); |
| 5269 | return null; |
| 5270 | } |
| 5271 | String iccId = card.getIccId(); |
| 5272 | if (TextUtils.isEmpty(iccId)) { |
| 5273 | loge("getIccId: ICC ID is null or empty."); |
| 5274 | return null; |
| 5275 | } |
| 5276 | return iccId; |
| 5277 | } |
| 5278 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5279 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5280 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5281 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5282 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5283 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5284 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | final long identity = Binder.clearCallingIdentity(); |
| 5286 | try { |
| 5287 | final String iccId = getIccId(subId); |
| 5288 | final Phone phone = getPhone(subId); |
| 5289 | if (phone == null) { |
| 5290 | return false; |
| 5291 | } |
| 5292 | final String subscriberId = phone.getSubscriberId(); |
| 5293 | |
| 5294 | if (DBG_MERGE) { |
| 5295 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5296 | + subscriberId + " to " + number); |
| 5297 | } |
| 5298 | |
| 5299 | if (TextUtils.isEmpty(iccId)) { |
| 5300 | return false; |
| 5301 | } |
| 5302 | |
| 5303 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5304 | |
| 5305 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5306 | if (alphaTag == null) { |
| 5307 | editor.remove(alphaTagPrefKey); |
| 5308 | } else { |
| 5309 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5310 | } |
| 5311 | |
| 5312 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5313 | // track all merged IMSIs based on line number |
| 5314 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5315 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5316 | if (number == null) { |
| 5317 | editor.remove(numberPrefKey); |
| 5318 | editor.remove(subscriberPrefKey); |
| 5319 | } else { |
| 5320 | editor.putString(numberPrefKey, number); |
| 5321 | editor.putString(subscriberPrefKey, subscriberId); |
| 5322 | } |
| 5323 | |
| 5324 | editor.commit(); |
| 5325 | return true; |
| 5326 | } finally { |
| 5327 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5328 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5332 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5333 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5334 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5335 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5336 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5337 | return null; |
| 5338 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5339 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5340 | final long identity = Binder.clearCallingIdentity(); |
| 5341 | try { |
| 5342 | String iccId = getIccId(subId); |
| 5343 | if (iccId != null) { |
| 5344 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5345 | if (DBG_MERGE) { |
| 5346 | log("getLine1NumberForDisplay returning " |
| 5347 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5348 | } |
| 5349 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5350 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5351 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5352 | return null; |
| 5353 | } finally { |
| 5354 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5355 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5356 | } |
| 5357 | |
| 5358 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5359 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5360 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5361 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5362 | return null; |
| 5363 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5364 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5365 | final long identity = Binder.clearCallingIdentity(); |
| 5366 | try { |
| 5367 | String iccId = getIccId(subId); |
| 5368 | if (iccId != null) { |
| 5369 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5370 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5371 | } |
| 5372 | return null; |
| 5373 | } finally { |
| 5374 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5375 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5376 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5377 | |
| 5378 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5379 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5380 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5381 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5382 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5383 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5384 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5385 | return null; |
| 5386 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5387 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5388 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5389 | // the process, where TelephonyManager was instantiated. |
| 5390 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5391 | final long identity = Binder.clearCallingIdentity(); |
| 5392 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5393 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5395 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5396 | |
| 5397 | // Figure out what subscribers are currently active |
| 5398 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5400 | // Only consider subs which match the current subId |
| 5401 | // This logic can be simplified. See b/131189269 for progress. |
| 5402 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5403 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5404 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5405 | |
| 5406 | // First pass, find a number override for an active subscriber |
| 5407 | String mergeNumber = null; |
| 5408 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5409 | for (String key : prefs.keySet()) { |
| 5410 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5411 | final String subscriberId = (String) prefs.get(key); |
| 5412 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5413 | final String iccId = key.substring( |
| 5414 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5415 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5416 | mergeNumber = (String) prefs.get(numberKey); |
| 5417 | if (DBG_MERGE) { |
| 5418 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5419 | + " for active subscriber " + subscriberId); |
| 5420 | } |
| 5421 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5422 | break; |
| 5423 | } |
| 5424 | } |
| 5425 | } |
| 5426 | } |
| 5427 | |
| 5428 | // Shortcut when no active merged subscribers |
| 5429 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5430 | return null; |
| 5431 | } |
| 5432 | |
| 5433 | // Second pass, find all subscribers under that line override |
| 5434 | final ArraySet<String> result = new ArraySet<>(); |
| 5435 | for (String key : prefs.keySet()) { |
| 5436 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5437 | final String number = (String) prefs.get(key); |
| 5438 | if (mergeNumber.equals(number)) { |
| 5439 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5440 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5441 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5442 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5443 | result.add(subscriberId); |
| 5444 | } |
| 5445 | } |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5450 | Arrays.sort(resultArray); |
| 5451 | if (DBG_MERGE) { |
| 5452 | Slog.d(LOG_TAG, |
| 5453 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5454 | } |
| 5455 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5456 | } finally { |
| 5457 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5458 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5462 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5463 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5464 | |
| 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
| 5467 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5468 | TelephonyManager.class); |
| 5469 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5470 | if (subscriberId == null) { |
| 5471 | if (DBG) { |
| 5472 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5473 | + subId); |
| 5474 | } |
| 5475 | return null; |
| 5476 | } |
| 5477 | |
| 5478 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5479 | .getSubscriptionInfo(subId); |
| 5480 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5481 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5482 | if (groupUuid == null) { |
| 5483 | return new String[]{subscriberId}; |
| 5484 | } |
| 5485 | |
| 5486 | // Get all subscriberIds from the group. |
| 5487 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5488 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5489 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5490 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5491 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5492 | if (subscriberId != null) { |
| 5493 | mergedSubscriberIds.add(subscriberId); |
| 5494 | } |
| 5495 | } |
| 5496 | |
| 5497 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5498 | } finally { |
| 5499 | Binder.restoreCallingIdentity(identity); |
| 5500 | |
| 5501 | } |
| 5502 | } |
| 5503 | |
| 5504 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5505 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5506 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5507 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5508 | |
| 5509 | final long identity = Binder.clearCallingIdentity(); |
| 5510 | try { |
| 5511 | final Phone phone = getPhone(subId); |
| 5512 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5513 | } finally { |
| 5514 | Binder.restoreCallingIdentity(identity); |
| 5515 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5516 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5517 | |
| 5518 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5519 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5520 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5521 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5522 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | |
| 5524 | final long identity = Binder.clearCallingIdentity(); |
| 5525 | try { |
| 5526 | final Phone phone = getPhone(subId); |
| 5527 | if (phone == null) { |
| 5528 | return false; |
| 5529 | } |
| 5530 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5531 | cdmaNonRoamingList); |
| 5532 | } finally { |
| 5533 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5534 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5538 | @Deprecated |
| 5539 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5540 | enforceModifyPermission(); |
| 5541 | |
| 5542 | int returnValue = 0; |
| 5543 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5544 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5545 | if(result.exception == null) { |
| 5546 | if (result.result != null) { |
| 5547 | byte[] responseData = (byte[])(result.result); |
| 5548 | if(responseData.length > oemResp.length) { |
| 5549 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5550 | responseData.length + "bytes. Buffer Size is " + |
| 5551 | oemResp.length + "bytes."); |
| 5552 | } |
| 5553 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5554 | returnValue = responseData.length; |
| 5555 | } |
| 5556 | } else { |
| 5557 | CommandException ex = (CommandException) result.exception; |
| 5558 | returnValue = ex.getCommandError().ordinal(); |
| 5559 | if(returnValue > 0) returnValue *= -1; |
| 5560 | } |
| 5561 | } catch (RuntimeException e) { |
| 5562 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5563 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5564 | if(returnValue > 0) returnValue *= -1; |
| 5565 | } |
| 5566 | |
| 5567 | return returnValue; |
| 5568 | } |
| 5569 | |
| 5570 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5571 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5572 | try { |
| 5573 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5574 | } catch (RuntimeException e) { |
| 5575 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5576 | } |
| 5577 | } |
| 5578 | |
| 5579 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5580 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5581 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5582 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5583 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5584 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5585 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | final long identity = Binder.clearCallingIdentity(); |
| 5587 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5588 | TelephonyPermissions |
| 5589 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5590 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5591 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5592 | } finally { |
| 5593 | Binder.restoreCallingIdentity(identity); |
| 5594 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5595 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5596 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5597 | |
| 5598 | @Override |
| 5599 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5600 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5601 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5602 | |
| 5603 | final long identity = Binder.clearCallingIdentity(); |
| 5604 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5605 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5606 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5607 | } finally { |
| 5608 | Binder.restoreCallingIdentity(identity); |
| 5609 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5613 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5614 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5615 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5616 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5617 | return false; |
| 5618 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5620 | final long identity = Binder.clearCallingIdentity(); |
| 5621 | try { |
| 5622 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5623 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5624 | // In the long run, we may instead need to check if there exists a connection service |
| 5625 | // which can support video calling. |
| 5626 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5627 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5628 | return imsManager.isVtEnabledByPlatform() |
| 5629 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5630 | && imsManager.isVtEnabledByUser(); |
| 5631 | } finally { |
| 5632 | Binder.restoreCallingIdentity(identity); |
| 5633 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5634 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5635 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5636 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5638 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5639 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5640 | return false; |
| 5641 | } |
| 5642 | |
| 5643 | final long identity = Binder.clearCallingIdentity(); |
| 5644 | try { |
| 5645 | CarrierConfigManager configManager = |
| 5646 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5647 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5648 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5649 | } finally { |
| 5650 | Binder.restoreCallingIdentity(identity); |
| 5651 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5655 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5656 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5657 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5658 | return false; |
| 5659 | } |
| 5660 | |
| 5661 | final long identity = Binder.clearCallingIdentity(); |
| 5662 | try { |
| 5663 | CarrierConfigManager configManager = |
| 5664 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5665 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5667 | } finally { |
| 5668 | Binder.restoreCallingIdentity(identity); |
| 5669 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5670 | } |
| 5671 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5672 | @Override |
| 5673 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 5674 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5675 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | @Override |
| 5679 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5680 | final long identity = Binder.clearCallingIdentity(); |
| 5681 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5682 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
| 5685 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5688 | /** |
| 5689 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5690 | * support for the feature and device firmware support. |
| 5691 | * |
| 5692 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5693 | */ |
| 5694 | @Override |
| 5695 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5697 | final Phone phone = getPhone(subscriptionId); |
| 5698 | if (phone == null) { |
| 5699 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5700 | return false; |
| 5701 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5703 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5705 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5706 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5707 | return isCarrierSupported && isDeviceSupported; |
| 5708 | } finally { |
| 5709 | Binder.restoreCallingIdentity(identity); |
| 5710 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5711 | } |
| 5712 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5713 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5714 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5715 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5716 | * 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] | 5717 | */ |
| 5718 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | final long identity = Binder.clearCallingIdentity(); |
| 5720 | try { |
Hall Liu | 81eb08c | 2019-10-29 16:50:20 -0700 | [diff] [blame] | 5721 | return isRttSupported(subscriptionId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5722 | } finally { |
| 5723 | Binder.restoreCallingIdentity(identity); |
| 5724 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5725 | } |
| 5726 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5727 | /** |
| 5728 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5729 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5730 | * |
| 5731 | * <p>Requires Permission: |
| 5732 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5733 | */ |
| 5734 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5735 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5736 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5737 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5738 | return null; |
| 5739 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5740 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5741 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5742 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5743 | return null; |
| 5744 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | |
| 5746 | final long identity = Binder.clearCallingIdentity(); |
| 5747 | try { |
| 5748 | return phone.getDeviceId(); |
| 5749 | } finally { |
| 5750 | Binder.restoreCallingIdentity(identity); |
| 5751 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5752 | } |
| 5753 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5754 | /** |
| 5755 | * {@hide} |
| 5756 | * Returns the IMS Registration Status on a particular subid |
| 5757 | * |
| 5758 | * @param subId |
| 5759 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5760 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5761 | Phone phone = getPhone(subId); |
| 5762 | if (phone != null) { |
| 5763 | return phone.isImsRegistered(); |
| 5764 | } else { |
| 5765 | return false; |
| 5766 | } |
| 5767 | } |
| 5768 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5769 | @Override |
| 5770 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | final long identity = Binder.clearCallingIdentity(); |
| 5772 | try { |
| 5773 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
| 5776 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5777 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5778 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5779 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5780 | public int getSubIdForPhoneAccountHandle( |
| 5781 | PhoneAccountHandle phoneAccountHandle, String callingPackage) { |
| 5782 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
| 5783 | callingPackage, "getSubIdForPhoneAccountHandle")) { |
| 5784 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 5785 | } |
| 5786 | final long identity = Binder.clearCallingIdentity(); |
| 5787 | try { |
| 5788 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 5789 | } finally { |
| 5790 | Binder.restoreCallingIdentity(identity); |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5795 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5796 | final long identity = Binder.clearCallingIdentity(); |
| 5797 | try { |
| 5798 | Phone phone = getPhone(subscriptionId); |
| 5799 | if (phone == null) { |
| 5800 | return null; |
| 5801 | } |
| 5802 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5803 | } finally { |
| 5804 | Binder.restoreCallingIdentity(identity); |
| 5805 | } |
| 5806 | } |
| 5807 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5808 | /** |
| 5809 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5810 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5811 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5812 | final long identity = Binder.clearCallingIdentity(); |
| 5813 | try { |
| 5814 | Phone phone = getPhone(subId); |
| 5815 | if (phone != null) { |
| 5816 | return phone.isWifiCallingEnabled(); |
| 5817 | } else { |
| 5818 | return false; |
| 5819 | } |
| 5820 | } finally { |
| 5821 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5822 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5825 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5826 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5827 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5828 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5829 | final long identity = Binder.clearCallingIdentity(); |
| 5830 | try { |
| 5831 | Phone phone = getPhone(subId); |
| 5832 | if (phone != null) { |
| 5833 | return phone.isVideoEnabled(); |
| 5834 | } else { |
| 5835 | return false; |
| 5836 | } |
| 5837 | } finally { |
| 5838 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | /** |
| 5843 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5844 | * defined in {@link ImsRegistrationImplBase}. |
| 5845 | */ |
| 5846 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | final long identity = Binder.clearCallingIdentity(); |
| 5848 | try { |
| 5849 | Phone phone = getPhone(subId); |
| 5850 | if (phone != null) { |
| 5851 | return phone.getImsRegistrationTech(); |
| 5852 | } else { |
| 5853 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5854 | } |
| 5855 | } finally { |
| 5856 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5857 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5858 | } |
| 5859 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5860 | @Override |
| 5861 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 5862 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5863 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5864 | return; |
| 5865 | } |
| 5866 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5867 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5868 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5869 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5870 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5871 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5872 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5873 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5874 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5875 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5876 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5877 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5878 | // There has been issues when Sms raw table somehow stores orphan |
| 5879 | // fragments. They lead to garbled message when new fragments come |
| 5880 | // in and combined with those stale ones. In case this happens again, |
| 5881 | // user can reset all network settings which will clean up this table. |
| 5882 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5883 | // Clean up IMS settings as well here. |
| 5884 | int slotId = getSlotIndex(subId); |
| 5885 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5886 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 5887 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 5888 | |
| 5889 | // Erase modem config if erase modem on network setting is enabled. |
| 5890 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 5891 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 5892 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 5893 | sendEraseModemConfig(getDefaultPhone()); |
| 5894 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5895 | } finally { |
| 5896 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5897 | } |
| 5898 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5899 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5900 | private void cleanUpSmsRawTable(Context context) { |
| 5901 | ContentResolver resolver = context.getContentResolver(); |
| 5902 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5903 | resolver.delete(uri, null, null); |
| 5904 | } |
| 5905 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5906 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5907 | public String getSimLocaleForSubscriber(int subId) { |
| 5908 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5909 | final Phone phone = getPhone(subId); |
| 5910 | if (phone == null) { |
| 5911 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5912 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5913 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | final long identity = Binder.clearCallingIdentity(); |
| 5915 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5916 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5917 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5918 | if (info == null) { |
| 5919 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5920 | return null; |
| 5921 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5922 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5923 | // preferences (EF-PL and EF-LI)... |
| 5924 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5926 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5927 | if (localeFromDefaultSim != null) { |
| 5928 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5929 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5930 | + localeFromDefaultSim); |
| 5931 | return localeFromDefaultSim.toLanguageTag(); |
| 5932 | } else { |
| 5933 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 | } |
| 5935 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5936 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5937 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5938 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5939 | // the SIM and carrier preferences does not include a country we add the country |
| 5940 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 5941 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5942 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5943 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5944 | return mccLocale.toLanguageTag(); |
| 5945 | } |
| 5946 | |
| 5947 | if (DBG) log("No locale found - returning null"); |
| 5948 | return null; |
| 5949 | } finally { |
| 5950 | Binder.restoreCallingIdentity(identity); |
| 5951 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5955 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5956 | } |
| 5957 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | /** |
| 5959 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5960 | */ |
| 5961 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5962 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5963 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5964 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5965 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5966 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5967 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5968 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5969 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5970 | * representing the state of the modem. |
| 5971 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5972 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5973 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5974 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5975 | */ |
| 5976 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5977 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5978 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5979 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5980 | |
| 5981 | final long identity = Binder.clearCallingIdentity(); |
| 5982 | try { |
| 5983 | ModemActivityInfo ret = null; |
| 5984 | synchronized (mLastModemActivityInfo) { |
| 5985 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5986 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5987 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5988 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5989 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5990 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 5991 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5993 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | } |
| 5995 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5996 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5997 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5998 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5999 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6000 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6001 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6002 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6003 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6004 | } |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6005 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6006 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6007 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6008 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6009 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6010 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6011 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | Bundle bundle = new Bundle(); |
| 6013 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6014 | result.send(0, bundle); |
| 6015 | } finally { |
| 6016 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6017 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6018 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6019 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6020 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6021 | // less than total activity duration. |
| 6022 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6023 | if (info == null) { |
| 6024 | return false; |
| 6025 | } |
| 6026 | int activityDurationMs = |
| 6027 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6028 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6029 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6030 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6031 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6032 | } |
| 6033 | return (info.isValid() |
| 6034 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6035 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6036 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6037 | && (totalTxTimeMs <= activityDurationMs)); |
| 6038 | } |
| 6039 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6040 | /** |
| 6041 | * {@hide} |
| 6042 | * Returns the service state information on specified subscription. |
| 6043 | */ |
| 6044 | @Override |
| 6045 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6046 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6047 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6048 | return null; |
| 6049 | } |
| 6050 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6051 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6052 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6053 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6054 | .setCallingPackage(callingPackage) |
| 6055 | .setCallingPid(Binder.getCallingPid()) |
| 6056 | .setCallingUid(Binder.getCallingUid()) |
| 6057 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6058 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6059 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6060 | .build()); |
| 6061 | |
| 6062 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6063 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6064 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6065 | .setCallingPackage(callingPackage) |
| 6066 | .setCallingPid(Binder.getCallingPid()) |
| 6067 | .setCallingUid(Binder.getCallingUid()) |
| 6068 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6069 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6070 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6071 | .build()); |
| 6072 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6073 | boolean hasFinePermission = |
| 6074 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6075 | boolean hasCoarsePermission = |
| 6076 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6077 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6078 | final long identity = Binder.clearCallingIdentity(); |
| 6079 | try { |
| 6080 | final Phone phone = getPhone(subId); |
| 6081 | if (phone == null) { |
| 6082 | return null; |
| 6083 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6084 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6085 | ServiceState ss = phone.getServiceState(); |
| 6086 | |
| 6087 | // Scrub out the location info in ServiceState depending on what level of access |
| 6088 | // the caller has. |
| 6089 | if (hasFinePermission) return ss; |
| 6090 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 6091 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(identity); |
| 6094 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6095 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6096 | |
| 6097 | /** |
| 6098 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6099 | * |
| 6100 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6101 | * voicemail ringtone. |
| 6102 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6103 | * PhoneAccount. |
| 6104 | */ |
| 6105 | @Override |
| 6106 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | final long identity = Binder.clearCallingIdentity(); |
| 6108 | try { |
| 6109 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6110 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6111 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6112 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6113 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6114 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6115 | } finally { |
| 6116 | Binder.restoreCallingIdentity(identity); |
| 6117 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6118 | } |
| 6119 | |
| 6120 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6121 | * Sets the per-account voicemail ringtone. |
| 6122 | * |
| 6123 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6124 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6125 | * |
| 6126 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6127 | * voicemail ringtone. |
| 6128 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6129 | * PhoneAccount. |
| 6130 | */ |
| 6131 | @Override |
| 6132 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6133 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6134 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6135 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6136 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6137 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6138 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6139 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6140 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6141 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6142 | |
| 6143 | final long identity = Binder.clearCallingIdentity(); |
| 6144 | try { |
| 6145 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6146 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6147 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6148 | } |
| 6149 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6150 | } finally { |
| 6151 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6152 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6156 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6157 | * |
| 6158 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6159 | * voicemail vibration setting. |
| 6160 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6161 | */ |
| 6162 | @Override |
| 6163 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6164 | final long identity = Binder.clearCallingIdentity(); |
| 6165 | try { |
| 6166 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6167 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6168 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6169 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6170 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6172 | } finally { |
| 6173 | Binder.restoreCallingIdentity(identity); |
| 6174 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6175 | } |
| 6176 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6177 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6178 | * Sets the per-account voicemail vibration. |
| 6179 | * |
| 6180 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6181 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6182 | * |
| 6183 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6184 | * voicemail vibration setting. |
| 6185 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6186 | * specific PhoneAccount. |
| 6187 | */ |
| 6188 | @Override |
| 6189 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6190 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6191 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6192 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6193 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6194 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6195 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6196 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6197 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6198 | } |
| 6199 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6200 | final long identity = Binder.clearCallingIdentity(); |
| 6201 | try { |
| 6202 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6203 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6204 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6205 | } |
| 6206 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6207 | } finally { |
| 6208 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6209 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6213 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6214 | * |
| 6215 | * @throws SecurityException if the caller does not have the required permission |
| 6216 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6217 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6218 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6219 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6220 | } |
| 6221 | |
| 6222 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6223 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6224 | * permission. |
| 6225 | * |
| 6226 | * @throws SecurityException if the caller does not have the required permission |
| 6227 | */ |
| 6228 | private void enforceSendSmsPermission() { |
| 6229 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6230 | } |
| 6231 | |
| 6232 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6233 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6234 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6235 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6236 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6237 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6238 | final long identity = Binder.clearCallingIdentity(); |
| 6239 | try { |
| 6240 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6241 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | if (componentName == null) { |
| 6243 | throw new SecurityException( |
| 6244 | "Caller not current active visual voicemail package[null]"); |
| 6245 | } |
| 6246 | String vvmPackage = componentName.getPackageName(); |
| 6247 | if (!callingPackage.equals(vvmPackage)) { |
| 6248 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6249 | + vvmPackage + "]"); |
| 6250 | } |
| 6251 | } finally { |
| 6252 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6253 | } |
| 6254 | } |
| 6255 | |
| 6256 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6257 | * Return the application ID for the app type. |
| 6258 | * |
| 6259 | * @param subId the subscription ID that this request applies to. |
| 6260 | * @param appType the uicc app type. |
| 6261 | * @return Application ID for specificied app type, or null if no uicc. |
| 6262 | */ |
| 6263 | @Override |
| 6264 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6265 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6266 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | |
| 6268 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6269 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | if (phone == null) { |
| 6271 | return null; |
| 6272 | } |
| 6273 | String aid = null; |
| 6274 | try { |
| 6275 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6276 | .getApplicationByType(appType).getAid(); |
| 6277 | } catch (Exception e) { |
| 6278 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6279 | } |
| 6280 | return aid; |
| 6281 | } finally { |
| 6282 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6283 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6284 | } |
| 6285 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6286 | /** |
| 6287 | * Return the Electronic Serial Number. |
| 6288 | * |
| 6289 | * @param subId the subscription ID that this request applies to. |
| 6290 | * @return ESN or null if error. |
| 6291 | */ |
| 6292 | @Override |
| 6293 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6294 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6295 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6296 | |
| 6297 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6298 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | if (phone == null) { |
| 6300 | return null; |
| 6301 | } |
| 6302 | String esn = null; |
| 6303 | try { |
| 6304 | esn = phone.getEsn(); |
| 6305 | } catch (Exception e) { |
| 6306 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6307 | } |
| 6308 | return esn; |
| 6309 | } finally { |
| 6310 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6311 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6312 | } |
| 6313 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6314 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6315 | * Return the Preferred Roaming List Version. |
| 6316 | * |
| 6317 | * @param subId the subscription ID that this request applies to. |
| 6318 | * @return PRLVersion or null if error. |
| 6319 | */ |
| 6320 | @Override |
| 6321 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6322 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6323 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6324 | |
| 6325 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6326 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6327 | if (phone == null) { |
| 6328 | return null; |
| 6329 | } |
| 6330 | String cdmaPrlVersion = null; |
| 6331 | try { |
| 6332 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6333 | } catch (Exception e) { |
| 6334 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6335 | } |
| 6336 | return cdmaPrlVersion; |
| 6337 | } finally { |
| 6338 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6339 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6343 | * Get snapshot of Telephony histograms |
| 6344 | * @return List of Telephony histograms |
| 6345 | * @hide |
| 6346 | */ |
| 6347 | @Override |
| 6348 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6349 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6350 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6351 | |
| 6352 | final long identity = Binder.clearCallingIdentity(); |
| 6353 | try { |
| 6354 | return RIL.getTelephonyRILTimingHistograms(); |
| 6355 | } finally { |
| 6356 | Binder.restoreCallingIdentity(identity); |
| 6357 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6358 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6359 | |
| 6360 | /** |
| 6361 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6362 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6363 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6364 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6365 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6366 | * @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] | 6367 | */ |
| 6368 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6369 | @TelephonyManager.SetCarrierRestrictionResult |
| 6370 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6371 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6372 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6373 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6374 | if (carrierRestrictionRules == null) { |
| 6375 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6376 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6377 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6378 | final long identity = Binder.clearCallingIdentity(); |
| 6379 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6380 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6381 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | } finally { |
| 6383 | Binder.restoreCallingIdentity(identity); |
| 6384 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | /** |
| 6388 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6389 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6390 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6391 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6392 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6393 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6394 | */ |
| 6395 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6396 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6397 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6398 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6399 | |
| 6400 | final long identity = Binder.clearCallingIdentity(); |
| 6401 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6402 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6403 | if (response instanceof CarrierRestrictionRules) { |
| 6404 | return (CarrierRestrictionRules) response; |
| 6405 | } |
| 6406 | // Response is an Exception of some kind, |
| 6407 | // which is signalled to the user as a NULL retval |
| 6408 | return null; |
| 6409 | } catch (Exception e) { |
| 6410 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6411 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | } finally { |
| 6413 | Binder.restoreCallingIdentity(identity); |
| 6414 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6415 | } |
| 6416 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6417 | /** |
| 6418 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6419 | * @param subId the subscription ID that this action applies to. |
| 6420 | * @param enabled control enable or disable metered apns. |
| 6421 | * {@hide} |
| 6422 | */ |
| 6423 | @Override |
| 6424 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6425 | enforceModifyPermission(); |
| 6426 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6427 | |
| 6428 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6429 | if (phone == null) { |
| 6430 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6431 | return; |
| 6432 | } |
| 6433 | try { |
| 6434 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6435 | } catch (Exception e) { |
| 6436 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6437 | } finally { |
| 6438 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6439 | } |
| 6440 | } |
| 6441 | |
| 6442 | /** |
| 6443 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6444 | * @param subId the subscription ID that this action applies to. |
| 6445 | * @param enabled control enable or disable radio. |
| 6446 | * {@hide} |
| 6447 | */ |
| 6448 | @Override |
| 6449 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6450 | enforceModifyPermission(); |
| 6451 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6452 | |
| 6453 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6454 | if (phone == null) { |
| 6455 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6456 | return; |
| 6457 | } |
| 6458 | try { |
| 6459 | phone.carrierActionSetRadioEnabled(enabled); |
| 6460 | } catch (Exception e) { |
| 6461 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6462 | } finally { |
| 6463 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6464 | } |
| 6465 | } |
| 6466 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6467 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6468 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6469 | * network status based on which carrier apps could apply actions accordingly, |
| 6470 | * enable/disable default url handler for example. |
| 6471 | * |
| 6472 | * @param subId the subscription ID that this action applies to. |
| 6473 | * @param report control start/stop reporting the default network status. |
| 6474 | * {@hide} |
| 6475 | */ |
| 6476 | @Override |
| 6477 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6478 | enforceModifyPermission(); |
| 6479 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6480 | |
| 6481 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6482 | if (phone == null) { |
| 6483 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6484 | return; |
| 6485 | } |
| 6486 | try { |
| 6487 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6488 | } catch (Exception e) { |
| 6489 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6490 | } finally { |
| 6491 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6492 | } |
| 6493 | } |
| 6494 | |
| 6495 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6496 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6497 | * @param subId the subscription ID that this action applies to. |
| 6498 | * {@hide} |
| 6499 | */ |
| 6500 | @Override |
| 6501 | public void carrierActionResetAll(int subId) { |
| 6502 | enforceModifyPermission(); |
| 6503 | final Phone phone = getPhone(subId); |
| 6504 | if (phone == null) { |
| 6505 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6506 | return; |
| 6507 | } |
| 6508 | try { |
| 6509 | phone.carrierActionResetAll(); |
| 6510 | } catch (Exception e) { |
| 6511 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6512 | } |
| 6513 | } |
| 6514 | |
| 6515 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6516 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6517 | * bug report is being generated. |
| 6518 | */ |
| 6519 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6520 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6521 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6522 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6523 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6524 | + Binder.getCallingPid() |
| 6525 | + ", uid=" + Binder.getCallingUid() |
| 6526 | + "without permission " |
| 6527 | + android.Manifest.permission.DUMP); |
| 6528 | return; |
| 6529 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6530 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6531 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6532 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6533 | @Override |
| 6534 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6535 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6536 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 6537 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 6538 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6539 | } |
| 6540 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6541 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6542 | * Get aggregated video call data usage since boot. |
| 6543 | * |
| 6544 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6545 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6546 | * {@hide} |
| 6547 | */ |
| 6548 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6549 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6550 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6551 | null); |
| 6552 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6553 | final long identity = Binder.clearCallingIdentity(); |
| 6554 | try { |
| 6555 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6556 | // records the delta with the corresponding network identity. |
| 6557 | // We just return the total video call data usage snapshot since boot. |
| 6558 | Phone phone = getPhone(subId); |
| 6559 | if (phone != null) { |
| 6560 | return phone.getVtDataUsage(perUidStats); |
| 6561 | } |
| 6562 | return null; |
| 6563 | } finally { |
| 6564 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6565 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6566 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6567 | |
| 6568 | /** |
| 6569 | * Policy control of data connection. Usually used when data limit is passed. |
| 6570 | * @param enabled True if enabling the data, otherwise disabling. |
| 6571 | * @param subId Subscription index |
| 6572 | * {@hide} |
| 6573 | */ |
| 6574 | @Override |
| 6575 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6576 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6577 | |
| 6578 | final long identity = Binder.clearCallingIdentity(); |
| 6579 | try { |
| 6580 | Phone phone = getPhone(subId); |
| 6581 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6582 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | } |
| 6584 | } finally { |
| 6585 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6586 | } |
| 6587 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6588 | |
| 6589 | /** |
| 6590 | * Get Client request stats |
| 6591 | * @return List of Client Request Stats |
| 6592 | * @hide |
| 6593 | */ |
| 6594 | @Override |
| 6595 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6596 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6597 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6598 | return null; |
| 6599 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6600 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6602 | final long identity = Binder.clearCallingIdentity(); |
| 6603 | try { |
| 6604 | if (phone != null) { |
| 6605 | return phone.getClientRequestStats(); |
| 6606 | } |
| 6607 | |
| 6608 | return null; |
| 6609 | } finally { |
| 6610 | Binder.restoreCallingIdentity(identity); |
| 6611 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6612 | } |
| 6613 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6614 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6615 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6616 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6617 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6618 | |
| 6619 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6620 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6621 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6622 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6623 | * @param state State of SIM (power down, power up, pass through) |
| 6624 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6625 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6626 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6627 | * |
| 6628 | **/ |
| 6629 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6630 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6631 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6632 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6633 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6634 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | final long identity = Binder.clearCallingIdentity(); |
| 6637 | try { |
| 6638 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6639 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6640 | } |
| 6641 | } finally { |
| 6642 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6643 | } |
| 6644 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6645 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6646 | private boolean isUssdApiAllowed(int subId) { |
| 6647 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6648 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6649 | if (configManager == null) { |
| 6650 | return false; |
| 6651 | } |
| 6652 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6653 | if (pb == null) { |
| 6654 | return false; |
| 6655 | } |
| 6656 | return pb.getBoolean( |
| 6657 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6658 | } |
| 6659 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6660 | /** |
| 6661 | * Check if phone is in emergency callback mode |
| 6662 | * @return true if phone is in emergency callback mode |
| 6663 | * @param subId sub id |
| 6664 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6665 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6666 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6667 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6668 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6669 | |
| 6670 | final long identity = Binder.clearCallingIdentity(); |
| 6671 | try { |
| 6672 | if (phone != null) { |
| 6673 | return phone.isInEcm(); |
| 6674 | } else { |
| 6675 | return false; |
| 6676 | } |
| 6677 | } finally { |
| 6678 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6679 | } |
| 6680 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6681 | |
| 6682 | /** |
| 6683 | * Get the current signal strength information for the given subscription. |
| 6684 | * Because this information is not updated when the device is in a low power state |
| 6685 | * it should not be relied-upon to be current. |
| 6686 | * @param subId Subscription index |
| 6687 | * @return the most recent cached signal strength info from the modem |
| 6688 | */ |
| 6689 | @Override |
| 6690 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6691 | final long identity = Binder.clearCallingIdentity(); |
| 6692 | try { |
| 6693 | Phone p = getPhone(subId); |
| 6694 | if (p == null) { |
| 6695 | return null; |
| 6696 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6697 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6698 | return p.getSignalStrength(); |
| 6699 | } finally { |
| 6700 | Binder.restoreCallingIdentity(identity); |
| 6701 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6702 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6703 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6704 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6705 | * Get the current modem radio state for the given slot. |
| 6706 | * @param slotIndex slot index. |
| 6707 | * @param callingPackage the name of the package making the call. |
| 6708 | * @return the current radio power state from the modem |
| 6709 | */ |
| 6710 | @Override |
| 6711 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6712 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6713 | if (phone != null) { |
| 6714 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6715 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6716 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6717 | } |
| 6718 | |
| 6719 | final long identity = Binder.clearCallingIdentity(); |
| 6720 | try { |
| 6721 | return phone.getRadioPowerState(); |
| 6722 | } finally { |
| 6723 | Binder.restoreCallingIdentity(identity); |
| 6724 | } |
| 6725 | } |
| 6726 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6727 | } |
| 6728 | |
| 6729 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6730 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6731 | * |
| 6732 | * <p>Requires one of the following permissions: |
| 6733 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6734 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6735 | * privileges. |
| 6736 | * |
| 6737 | * @param subId subscription id |
| 6738 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6739 | * {@code false}. |
| 6740 | */ |
| 6741 | @Override |
| 6742 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6743 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6744 | null /* message */); |
| 6745 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6746 | boolean isEnabled = false; |
| 6747 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6748 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6749 | Phone phone = getPhone(subId); |
| 6750 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6751 | } catch (Exception e) { |
| 6752 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6753 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6754 | } finally { |
| 6755 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6756 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6757 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6758 | } |
| 6759 | |
| 6760 | |
| 6761 | /** |
| 6762 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6763 | * |
| 6764 | * <p> Requires permission: |
| 6765 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6766 | * privileges. |
| 6767 | * |
| 6768 | * @param subId subscription id |
| 6769 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6770 | */ |
| 6771 | @Override |
| 6772 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6773 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6774 | mApp, subId, "setDataRoamingEnabled"); |
| 6775 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6776 | final long identity = Binder.clearCallingIdentity(); |
| 6777 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6778 | Phone phone = getPhone(subId); |
| 6779 | if (phone != null) { |
| 6780 | phone.setDataRoamingEnabled(isEnabled); |
| 6781 | } |
| 6782 | } finally { |
| 6783 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6784 | } |
| 6785 | } |
| 6786 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6787 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6788 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame^] | 6789 | TelephonyPermissions |
| 6790 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6791 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6792 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6793 | boolean isAllowed = true; |
| 6794 | final long identity = Binder.clearCallingIdentity(); |
| 6795 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6796 | Phone phone = getPhone(subId); |
| 6797 | if (phone != null) { |
| 6798 | isAllowed = phone.isCspPlmnEnabled(); |
| 6799 | } |
| 6800 | } finally { |
| 6801 | Binder.restoreCallingIdentity(identity); |
| 6802 | } |
| 6803 | return isAllowed; |
| 6804 | } |
| 6805 | |
| 6806 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6807 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6808 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6809 | try { |
| 6810 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6811 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6812 | } catch (SecurityException e) { |
| 6813 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6814 | // has carrier privileges on an active UICC |
| 6815 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6816 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6817 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6818 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6819 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6820 | |
| 6821 | final long identity = Binder.clearCallingIdentity(); |
| 6822 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6823 | UiccController uiccController = UiccController.getInstance(); |
| 6824 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6825 | if (hasReadPermission) { |
| 6826 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6827 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6828 | |
| 6829 | // Remove private info if the caller doesn't have access |
| 6830 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6831 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6832 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6833 | // is available |
| 6834 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6835 | if (card == null || card.getUiccProfile() == null) { |
| 6836 | // assume no access if the card or profile is unavailable |
| 6837 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6838 | continue; |
| 6839 | } |
| 6840 | UiccProfile profile = card.getUiccProfile(); |
| 6841 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6842 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6843 | filteredInfos.add(cardInfo); |
| 6844 | } else { |
| 6845 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6846 | } |
| 6847 | } |
| 6848 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6849 | } finally { |
| 6850 | Binder.restoreCallingIdentity(identity); |
| 6851 | } |
| 6852 | } |
| 6853 | |
| 6854 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6855 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6856 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6857 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6858 | final long identity = Binder.clearCallingIdentity(); |
| 6859 | try { |
| 6860 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6861 | if (slots == null) { |
| 6862 | Rlog.i(LOG_TAG, "slots is null."); |
| 6863 | return null; |
| 6864 | } |
| 6865 | |
| 6866 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6867 | for (int i = 0; i < slots.length; i++) { |
| 6868 | UiccSlot slot = slots[i]; |
| 6869 | if (slot == null) { |
| 6870 | continue; |
| 6871 | } |
| 6872 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6873 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | UiccCard card = slot.getUiccCard(); |
| 6875 | if (card != null) { |
| 6876 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6877 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6878 | cardId = slot.getEid(); |
| 6879 | if (TextUtils.isEmpty(cardId)) { |
| 6880 | cardId = slot.getIccId(); |
| 6881 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6882 | } |
| 6883 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6884 | if (cardId != null) { |
| 6885 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6886 | // if cardId is an EID, it's all digits so this is fine |
| 6887 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6888 | } |
| 6889 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6890 | int cardState = 0; |
| 6891 | switch (slot.getCardState()) { |
| 6892 | case CARDSTATE_ABSENT: |
| 6893 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6894 | break; |
| 6895 | case CARDSTATE_PRESENT: |
| 6896 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6897 | break; |
| 6898 | case CARDSTATE_ERROR: |
| 6899 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6900 | break; |
| 6901 | case CARDSTATE_RESTRICTED: |
| 6902 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6903 | break; |
| 6904 | default: |
| 6905 | break; |
| 6906 | |
| 6907 | } |
| 6908 | |
| 6909 | infos[i] = new UiccSlotInfo( |
| 6910 | slot.isActive(), |
| 6911 | slot.isEuicc(), |
| 6912 | cardId, |
| 6913 | cardState, |
| 6914 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6915 | slot.isExtendedApduSupported(), |
| 6916 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6917 | } |
| 6918 | return infos; |
| 6919 | } finally { |
| 6920 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6921 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6922 | } |
| 6923 | |
| 6924 | @Override |
| 6925 | public boolean switchSlots(int[] physicalSlots) { |
| 6926 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6927 | |
| 6928 | final long identity = Binder.clearCallingIdentity(); |
| 6929 | try { |
| 6930 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6931 | } finally { |
| 6932 | Binder.restoreCallingIdentity(identity); |
| 6933 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6934 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6935 | |
| 6936 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6937 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6938 | final long identity = Binder.clearCallingIdentity(); |
| 6939 | try { |
| 6940 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6941 | } finally { |
| 6942 | Binder.restoreCallingIdentity(identity); |
| 6943 | } |
| 6944 | } |
| 6945 | |
| 6946 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6947 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6948 | enforceModifyPermission(); |
| 6949 | final Phone phone = getPhone(subId); |
| 6950 | if (phone == null) { |
| 6951 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6952 | return; |
| 6953 | } |
| 6954 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6955 | final long identity = Binder.clearCallingIdentity(); |
| 6956 | try { |
| 6957 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6958 | } finally { |
| 6959 | Binder.restoreCallingIdentity(identity); |
| 6960 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6961 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6962 | |
| 6963 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6964 | * A test API to reload the UICC profile. |
| 6965 | * |
| 6966 | * <p>Requires that the calling app has permission |
| 6967 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6968 | * @hide |
| 6969 | */ |
| 6970 | @Override |
| 6971 | public void refreshUiccProfile(int subId) { |
| 6972 | enforceModifyPermission(); |
| 6973 | |
| 6974 | final long identity = Binder.clearCallingIdentity(); |
| 6975 | try { |
| 6976 | Phone phone = getPhone(subId); |
| 6977 | if (phone == null) { |
| 6978 | return; |
| 6979 | } |
| 6980 | UiccCard uiccCard = phone.getUiccCard(); |
| 6981 | if (uiccCard == null) { |
| 6982 | return; |
| 6983 | } |
| 6984 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6985 | if (uiccProfile == null) { |
| 6986 | return; |
| 6987 | } |
| 6988 | uiccProfile.refresh(); |
| 6989 | } finally { |
| 6990 | Binder.restoreCallingIdentity(identity); |
| 6991 | } |
| 6992 | } |
| 6993 | |
| 6994 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6995 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6996 | */ |
| 6997 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 6998 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6999 | } |
| 7000 | |
| 7001 | /** |
| 7002 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7003 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7004 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7005 | */ |
| 7006 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7007 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7008 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7009 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7010 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7011 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7012 | return isDataRoamingEnabled; |
| 7013 | } |
| 7014 | |
| 7015 | /** |
| 7016 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7017 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7018 | */ |
| 7019 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7020 | List<Integer> list = TelephonyProperties.default_network(); |
| 7021 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7022 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7023 | return list.get(phoneId); |
| 7024 | } |
| 7025 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7026 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7027 | |
| 7028 | @Override |
| 7029 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7030 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7031 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7032 | |
| 7033 | final long identity = Binder.clearCallingIdentity(); |
| 7034 | try { |
| 7035 | final Phone phone = getPhone(subId); |
| 7036 | if (phone == null) { |
| 7037 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7038 | return; |
| 7039 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7040 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7041 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7042 | } finally { |
| 7043 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7044 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | @Override |
| 7048 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7049 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | |
| 7051 | final long identity = Binder.clearCallingIdentity(); |
| 7052 | try { |
| 7053 | final Phone phone = getPhone(subId); |
| 7054 | if (phone == null) { |
| 7055 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7056 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7057 | } |
| 7058 | return phone.getCarrierIdListVersion(); |
| 7059 | } finally { |
| 7060 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7061 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7062 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7063 | |
| 7064 | @Override |
| 7065 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 7066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7067 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 7068 | return -1; |
| 7069 | } |
| 7070 | |
| 7071 | final long identity = Binder.clearCallingIdentity(); |
| 7072 | try { |
| 7073 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7074 | } finally { |
| 7075 | Binder.restoreCallingIdentity(identity); |
| 7076 | } |
| 7077 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7078 | |
| 7079 | @Override |
| 7080 | public int getCdmaRoamingMode(int subId) { |
| 7081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7082 | mApp, subId, "getCdmaRoamingMode"); |
| 7083 | |
| 7084 | final long identity = Binder.clearCallingIdentity(); |
| 7085 | try { |
| 7086 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7087 | } finally { |
| 7088 | Binder.restoreCallingIdentity(identity); |
| 7089 | } |
| 7090 | } |
| 7091 | |
| 7092 | @Override |
| 7093 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7095 | mApp, subId, "setCdmaRoamingMode"); |
| 7096 | |
| 7097 | final long identity = Binder.clearCallingIdentity(); |
| 7098 | try { |
| 7099 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7100 | } finally { |
| 7101 | Binder.restoreCallingIdentity(identity); |
| 7102 | } |
| 7103 | } |
| 7104 | |
| 7105 | @Override |
| 7106 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7108 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7109 | |
| 7110 | final long identity = Binder.clearCallingIdentity(); |
| 7111 | try { |
| 7112 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7113 | } finally { |
| 7114 | Binder.restoreCallingIdentity(identity); |
| 7115 | } |
| 7116 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7117 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7118 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7119 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7120 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7121 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7122 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7123 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7124 | } |
| 7125 | final long identity = Binder.clearCallingIdentity(); |
| 7126 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7127 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7128 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7129 | if (phone.getEmergencyNumberTracker() != null |
| 7130 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7131 | emergencyNumberListInternal.put( |
| 7132 | phone.getSubId(), |
| 7133 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7134 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7135 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7136 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7137 | } finally { |
| 7138 | Binder.restoreCallingIdentity(identity); |
| 7139 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7143 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7144 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7145 | if (!exactMatch) { |
| 7146 | TelephonyPermissions |
| 7147 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7148 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7149 | } |
| 7150 | final long identity = Binder.clearCallingIdentity(); |
| 7151 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7152 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7153 | if (phone.getEmergencyNumberTracker() != null |
| 7154 | && phone.getEmergencyNumberTracker() != null) { |
| 7155 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7156 | number, exactMatch)) { |
| 7157 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7158 | } |
| 7159 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7160 | } |
| 7161 | return false; |
| 7162 | } finally { |
| 7163 | Binder.restoreCallingIdentity(identity); |
| 7164 | } |
| 7165 | } |
| 7166 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7167 | /** |
| 7168 | * Update emergency number list for test mode. |
| 7169 | */ |
| 7170 | @Override |
| 7171 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7172 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7173 | "updateEmergencyNumberListTestMode"); |
| 7174 | |
| 7175 | final long identity = Binder.clearCallingIdentity(); |
| 7176 | try { |
| 7177 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7178 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7179 | if (tracker != null) { |
| 7180 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7181 | } |
| 7182 | } |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
| 7185 | } |
| 7186 | } |
| 7187 | |
| 7188 | /** |
| 7189 | * Get the full emergency number list for test mode. |
| 7190 | */ |
| 7191 | @Override |
| 7192 | public List<String> getEmergencyNumberListTestMode() { |
| 7193 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7194 | "getEmergencyNumberListTestMode"); |
| 7195 | |
| 7196 | final long identity = Binder.clearCallingIdentity(); |
| 7197 | try { |
| 7198 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7199 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7200 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7201 | if (tracker != null) { |
| 7202 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7203 | emergencyNumbers.add(num.getNumber()); |
| 7204 | } |
| 7205 | } |
| 7206 | } |
| 7207 | return new ArrayList<>(emergencyNumbers); |
| 7208 | } finally { |
| 7209 | Binder.restoreCallingIdentity(identity); |
| 7210 | } |
| 7211 | } |
| 7212 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7213 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7214 | public int getEmergencyNumberDbVersion(int subId) { |
| 7215 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7216 | |
| 7217 | final long identity = Binder.clearCallingIdentity(); |
| 7218 | try { |
| 7219 | final Phone phone = getPhone(subId); |
| 7220 | if (phone == null) { |
| 7221 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7222 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7223 | } |
| 7224 | return phone.getEmergencyNumberDbVersion(); |
| 7225 | } finally { |
| 7226 | Binder.restoreCallingIdentity(identity); |
| 7227 | } |
| 7228 | } |
| 7229 | |
| 7230 | @Override |
| 7231 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7232 | enforceModifyPermission(); |
| 7233 | |
| 7234 | final long identity = Binder.clearCallingIdentity(); |
| 7235 | try { |
| 7236 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7237 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7238 | if (tracker != null) { |
| 7239 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7240 | } |
| 7241 | } |
| 7242 | } finally { |
| 7243 | Binder.restoreCallingIdentity(identity); |
| 7244 | } |
| 7245 | } |
| 7246 | |
| 7247 | @Override |
| 7248 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7249 | enforceActiveEmergencySessionPermission(); |
| 7250 | |
| 7251 | final long identity = Binder.clearCallingIdentity(); |
| 7252 | try { |
| 7253 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7254 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7255 | if (tracker != null) { |
| 7256 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7257 | } |
| 7258 | } |
| 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
| 7261 | } |
| 7262 | } |
| 7263 | |
| 7264 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7265 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7266 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7267 | Phone phone = getPhone(subId); |
| 7268 | if (phone == null) { |
| 7269 | return null; |
| 7270 | } |
| 7271 | final long identity = Binder.clearCallingIdentity(); |
| 7272 | try { |
| 7273 | UiccProfile profile = UiccController.getInstance() |
| 7274 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7275 | if (profile != null) { |
| 7276 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7277 | } |
| 7278 | } finally { |
| 7279 | Binder.restoreCallingIdentity(identity); |
| 7280 | } |
| 7281 | return null; |
| 7282 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7283 | |
| 7284 | /** |
| 7285 | * Enable or disable a modem stack. |
| 7286 | */ |
| 7287 | @Override |
| 7288 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7289 | enforceModifyPermission(); |
| 7290 | |
| 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
| 7293 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7294 | if (phone == null) { |
| 7295 | return false; |
| 7296 | } else { |
| 7297 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7298 | } |
| 7299 | } finally { |
| 7300 | Binder.restoreCallingIdentity(identity); |
| 7301 | } |
| 7302 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7303 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7304 | /** |
| 7305 | * Whether a modem stack is enabled or not. |
| 7306 | */ |
| 7307 | @Override |
| 7308 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7309 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7310 | if (phone == null) return false; |
| 7311 | |
| 7312 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7313 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7314 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7315 | } |
| 7316 | |
| 7317 | final long identity = Binder.clearCallingIdentity(); |
| 7318 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7319 | try { |
| 7320 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7321 | } catch (NoSuchElementException ex) { |
| 7322 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7323 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7324 | } finally { |
| 7325 | Binder.restoreCallingIdentity(identity); |
| 7326 | } |
| 7327 | } |
| 7328 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7329 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7330 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7331 | enforceModifyPermission(); |
| 7332 | |
| 7333 | final long identity = Binder.clearCallingIdentity(); |
| 7334 | try { |
| 7335 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7336 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7337 | .commit(); |
| 7338 | } finally { |
| 7339 | Binder.restoreCallingIdentity(identity); |
| 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7344 | @TelephonyManager.IsMultiSimSupportedResult |
| 7345 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7346 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7347 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7348 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7349 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7350 | |
| 7351 | final long identity = Binder.clearCallingIdentity(); |
| 7352 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7353 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7354 | } finally { |
| 7355 | Binder.restoreCallingIdentity(identity); |
| 7356 | } |
| 7357 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7358 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7359 | @TelephonyManager.IsMultiSimSupportedResult |
| 7360 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7361 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7362 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7363 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7364 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7365 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7366 | } |
| 7367 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7368 | // supported by the modem, indicate that it is restricted. |
| 7369 | PhoneCapability staticCapability = |
| 7370 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7371 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7372 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7373 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7374 | } |
| 7375 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7376 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7377 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7378 | } |
| 7379 | // Check if support of multiple SIMs is restricted by carrier |
| 7380 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7381 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7382 | } |
| 7383 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7384 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7385 | } |
| 7386 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7387 | /** |
| 7388 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7389 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7390 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7391 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7392 | * @param numOfSims number of active sims we want to switch to |
| 7393 | */ |
| 7394 | @Override |
| 7395 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7396 | if (numOfSims == 1) { |
| 7397 | enforceModifyPermission(); |
| 7398 | } else { |
| 7399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7400 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7401 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7402 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7403 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7404 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7405 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7406 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7407 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7408 | return; |
| 7409 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7410 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7411 | } finally { |
| 7412 | Binder.restoreCallingIdentity(identity); |
| 7413 | } |
| 7414 | } |
| 7415 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7416 | @Override |
| 7417 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7418 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7419 | Phone phone = getPhone(subId); |
| 7420 | if (phone == null) { |
| 7421 | return false; |
| 7422 | } |
| 7423 | final long identity = Binder.clearCallingIdentity(); |
| 7424 | try { |
| 7425 | UiccCard uiccCard = phone.getUiccCard(); |
| 7426 | if (uiccCard == null) { |
| 7427 | return false; |
| 7428 | } |
| 7429 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7430 | if (uiccProfile == null) { |
| 7431 | return false; |
| 7432 | } |
| 7433 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7434 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7435 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7436 | } |
| 7437 | return false; |
| 7438 | } finally { |
| 7439 | Binder.restoreCallingIdentity(identity); |
| 7440 | } |
| 7441 | } |
| 7442 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7443 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7444 | * Get whether making changes to modem configurations will trigger reboot. |
| 7445 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7446 | */ |
| 7447 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7448 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7449 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7450 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7451 | return false; |
| 7452 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7453 | final long identity = Binder.clearCallingIdentity(); |
| 7454 | try { |
| 7455 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7456 | } finally { |
| 7457 | Binder.restoreCallingIdentity(identity); |
| 7458 | } |
| 7459 | } |
| 7460 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7461 | private void updateModemStateMetrics() { |
| 7462 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7463 | // TODO: check the state for each modem if the api is ready. |
| 7464 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7465 | } |
| 7466 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7467 | @Override |
| 7468 | public int[] getSlotsMapping() { |
| 7469 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7470 | |
| 7471 | final long identity = Binder.clearCallingIdentity(); |
| 7472 | try { |
| 7473 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7474 | // All logical slots should have a mapping to a physical slot. |
| 7475 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7476 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7477 | for (int i = 0; i < slotInfos.length; i++) { |
| 7478 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7479 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7480 | } |
| 7481 | } |
| 7482 | return logicalSlotsMapping; |
| 7483 | } finally { |
| 7484 | Binder.restoreCallingIdentity(identity); |
| 7485 | } |
| 7486 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7487 | |
| 7488 | /** |
| 7489 | * Get the IRadio HAL Version |
| 7490 | */ |
| 7491 | @Override |
| 7492 | public int getRadioHalVersion() { |
| 7493 | Phone phone = getDefaultPhone(); |
| 7494 | if (phone == null) return -1; |
| 7495 | HalVersion hv = phone.getHalVersion(); |
| 7496 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7497 | return hv.major * 100 + hv.minor; |
| 7498 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7499 | |
| 7500 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7501 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7502 | * corresponding network requests on a subId. |
| 7503 | * |
| 7504 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7505 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7506 | * 2) APN is un-metered for this subscription, or |
| 7507 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7508 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7509 | * |
| 7510 | * @return whether data is allowed for a apn type. |
| 7511 | * |
| 7512 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7513 | */ |
| 7514 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7515 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7516 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7517 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7518 | |
| 7519 | // Now that all security checks passes, perform the operation as ourselves. |
| 7520 | final long identity = Binder.clearCallingIdentity(); |
| 7521 | try { |
| 7522 | Phone phone = getPhone(subId); |
| 7523 | if (phone == null) return false; |
| 7524 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7525 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7526 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7527 | } finally { |
| 7528 | Binder.restoreCallingIdentity(identity); |
| 7529 | } |
| 7530 | } |
| 7531 | |
| 7532 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7533 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7534 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7535 | |
| 7536 | // Now that all security checks passes, perform the operation as ourselves. |
| 7537 | final long identity = Binder.clearCallingIdentity(); |
| 7538 | try { |
| 7539 | Phone phone = getPhone(subId); |
| 7540 | if (phone == null) return true; // By default return true. |
| 7541 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7542 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7543 | } finally { |
| 7544 | Binder.restoreCallingIdentity(identity); |
| 7545 | } |
| 7546 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7547 | |
| 7548 | @Override |
| 7549 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7550 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7551 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7552 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7553 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7554 | } |
| 7555 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7556 | Intent intent = new Intent(); |
| 7557 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7558 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7559 | // Bring up choose default SMS subscription dialog right now |
| 7560 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7561 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7562 | mApp.startActivity(intent); |
| 7563 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7564 | |
| 7565 | @Override |
| 7566 | public String getMmsUAProfUrl(int subId) { |
| 7567 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7568 | final long identity = Binder.clearCallingIdentity(); |
| 7569 | try { |
| 7570 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7571 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7572 | } finally { |
| 7573 | Binder.restoreCallingIdentity(identity); |
| 7574 | } |
| 7575 | } |
| 7576 | |
| 7577 | @Override |
| 7578 | public String getMmsUserAgent(int subId) { |
| 7579 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7580 | final long identity = Binder.clearCallingIdentity(); |
| 7581 | try { |
| 7582 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7583 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7584 | } finally { |
| 7585 | Binder.restoreCallingIdentity(identity); |
| 7586 | } |
| 7587 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7588 | |
| 7589 | @Override |
| 7590 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7591 | enforceModifyPermission(); |
| 7592 | |
| 7593 | // Now that all security checks passes, perform the operation as ourselves. |
| 7594 | final long identity = Binder.clearCallingIdentity(); |
| 7595 | try { |
| 7596 | Phone phone = getPhone(subId); |
| 7597 | if (phone == null) return false; |
| 7598 | |
| 7599 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7600 | } finally { |
| 7601 | Binder.restoreCallingIdentity(identity); |
| 7602 | } |
| 7603 | } |
| 7604 | |
| 7605 | @Override |
| 7606 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7607 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7608 | |
| 7609 | // Now that all security checks passes, perform the operation as ourselves. |
| 7610 | final long identity = Binder.clearCallingIdentity(); |
| 7611 | try { |
| 7612 | Phone phone = getPhone(subId); |
| 7613 | if (phone == null) return false; |
| 7614 | |
| 7615 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7616 | } finally { |
| 7617 | Binder.restoreCallingIdentity(identity); |
| 7618 | } |
| 7619 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7620 | |
| 7621 | /** |
| 7622 | * Updates whether conference event pacakge handling is enabled. |
| 7623 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7624 | * otherwise. |
| 7625 | */ |
| 7626 | @Override |
| 7627 | public void setCepEnabled(boolean isCepEnabled) { |
| 7628 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7629 | |
| 7630 | final long identity = Binder.clearCallingIdentity(); |
| 7631 | try { |
| 7632 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7633 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7634 | Phone defaultPhone = phone.getImsPhone(); |
| 7635 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7636 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7637 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7638 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7639 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7640 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7641 | + imsPhone.getMsisdn()); |
| 7642 | } |
| 7643 | } |
| 7644 | } finally { |
| 7645 | Binder.restoreCallingIdentity(identity); |
| 7646 | } |
| 7647 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7648 | } |