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; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 55 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
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; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 136 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 157 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccIoResult; |
| 161 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccSlot; |
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 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 275 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 276 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 277 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 278 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 279 | /** The singleton instance. */ |
| 280 | private static PhoneInterfaceManager sInstance; |
| 281 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 282 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 283 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 284 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 285 | private AppOpsManager mAppOps; |
| 286 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 287 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 288 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 289 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 290 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 291 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 292 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 293 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 294 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 295 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 296 | // String to store multi SIM allowed |
| 297 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 298 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 299 | // The AID of ISD-R. |
| 300 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 301 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 302 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 303 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 304 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 305 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 306 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 307 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 308 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 309 | */ |
| 310 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 311 | "reset_network_erase_modem_config_enabled"; |
| 312 | |
| 313 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 314 | * A request object to use for transmitting data to an ICC. |
| 315 | */ |
| 316 | private static final class IccAPDUArgument { |
| 317 | public int channel, cla, command, p1, p2, p3; |
| 318 | public String data; |
| 319 | |
| 320 | public IccAPDUArgument(int channel, int cla, int command, |
| 321 | int p1, int p2, int p3, String data) { |
| 322 | this.channel = channel; |
| 323 | this.cla = cla; |
| 324 | this.command = command; |
| 325 | this.p1 = p1; |
| 326 | this.p2 = p2; |
| 327 | this.p3 = p3; |
| 328 | this.data = data; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 333 | * A request object to use for transmitting data to an ICC. |
| 334 | */ |
| 335 | private static final class ManualNetworkSelectionArgument { |
| 336 | public OperatorInfo operatorInfo; |
| 337 | public boolean persistSelection; |
| 338 | |
| 339 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 340 | this.operatorInfo = operatorInfo; |
| 341 | this.persistSelection = persistSelection; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 346 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 347 | * request after sending. The main thread will notify the request when it is complete. |
| 348 | */ |
| 349 | private static final class MainThreadRequest { |
| 350 | /** The argument to use for the request */ |
| 351 | public Object argument; |
| 352 | /** The result of the request that is run on the main thread */ |
| 353 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 354 | // The subscriber id that this request applies to. Defaults to |
| 355 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 356 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 357 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 358 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 359 | public Phone phone; |
| 360 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 361 | public WorkSource workSource; |
| 362 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 363 | public MainThreadRequest(Object argument) { |
| 364 | this.argument = argument; |
| 365 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 366 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 367 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 368 | this.argument = argument; |
| 369 | if (phone != null) { |
| 370 | this.phone = phone; |
| 371 | } |
| 372 | this.workSource = workSource; |
| 373 | } |
| 374 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 375 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 376 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 377 | if (subId != null) { |
| 378 | this.subId = subId; |
| 379 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 380 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 381 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 384 | private static final class IncomingThirdPartyCallArgs { |
| 385 | public final ComponentName component; |
| 386 | public final String callId; |
| 387 | public final String callerDisplayName; |
| 388 | |
| 389 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 390 | String callerDisplayName) { |
| 391 | this.component = component; |
| 392 | this.callId = callId; |
| 393 | this.callerDisplayName = callerDisplayName; |
| 394 | } |
| 395 | } |
| 396 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | /** |
| 398 | * A handler that processes messages on the main thread in the phone process. Since many |
| 399 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 400 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 401 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 402 | * on, which will be notified when the operation completes and will contain the result of the |
| 403 | * request. |
| 404 | * |
| 405 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 406 | * note that request.result must be set to something non-null for the calling thread to |
| 407 | * unblock. |
| 408 | */ |
| 409 | private final class MainThreadHandler extends Handler { |
| 410 | @Override |
| 411 | public void handleMessage(Message msg) { |
| 412 | MainThreadRequest request; |
| 413 | Message onCompleted; |
| 414 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 415 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 416 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 417 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | |
| 419 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 420 | case CMD_HANDLE_USSD_REQUEST: { |
| 421 | request = (MainThreadRequest) msg.obj; |
| 422 | final Phone phone = getPhoneFromRequest(request); |
| 423 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 424 | String ussdRequest = ussdObject.first; |
| 425 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 426 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 427 | if (!isUssdApiAllowed(request.subId)) { |
| 428 | // Carrier does not support use of this API, return failure. |
| 429 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 430 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 431 | Bundle returnData = new Bundle(); |
| 432 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 433 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 434 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 435 | request.result = true; |
| 436 | notifyRequester(request); |
| 437 | return; |
| 438 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 439 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 440 | try { |
| 441 | request.result = phone != null |
| 442 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 443 | } catch (CallStateException cse) { |
| 444 | request.result = false; |
| 445 | } |
| 446 | // Wake up the requesting thread |
| 447 | notifyRequester(request); |
| 448 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 451 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 452 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 453 | final Phone phone = getPhoneFromRequest(request); |
| 454 | request.result = phone != null ? |
| 455 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 456 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 457 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 458 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 459 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 460 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 461 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 462 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 463 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 464 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 465 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 466 | if (uiccCard == null) { |
| 467 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 468 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 469 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 470 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 471 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 472 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 473 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 474 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 475 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 476 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 477 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 478 | break; |
| 479 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 481 | ar = (AsyncResult) msg.obj; |
| 482 | request = (MainThreadRequest) ar.userObj; |
| 483 | if (ar.exception == null && ar.result != null) { |
| 484 | request.result = ar.result; |
| 485 | } else { |
| 486 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 487 | if (ar.result == null) { |
| 488 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 489 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 490 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 491 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 492 | } else { |
| 493 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 494 | } |
| 495 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 496 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 497 | break; |
| 498 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 499 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 500 | request = (MainThreadRequest) msg.obj; |
| 501 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 502 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 503 | if (uiccCard == null) { |
| 504 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 505 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 506 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 507 | } else { |
| 508 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 509 | request); |
| 510 | uiccCard.iccTransmitApduBasicChannel( |
| 511 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 512 | iccArgument.p3, iccArgument.data, onCompleted); |
| 513 | } |
| 514 | break; |
| 515 | |
| 516 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 517 | ar = (AsyncResult) msg.obj; |
| 518 | request = (MainThreadRequest) ar.userObj; |
| 519 | if (ar.exception == null && ar.result != null) { |
| 520 | request.result = ar.result; |
| 521 | } else { |
| 522 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 523 | if (ar.result == null) { |
| 524 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 525 | } else if (ar.exception instanceof CommandException) { |
| 526 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 527 | ar.exception); |
| 528 | } else { |
| 529 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 530 | } |
| 531 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 532 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 533 | break; |
| 534 | |
| 535 | case CMD_EXCHANGE_SIM_IO: |
| 536 | request = (MainThreadRequest) msg.obj; |
| 537 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 538 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | if (uiccCard == null) { |
| 540 | loge("iccExchangeSimIO: No UICC"); |
| 541 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 542 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 543 | } else { |
| 544 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 545 | request); |
| 546 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 547 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 548 | iccArgument.data, onCompleted); |
| 549 | } |
| 550 | break; |
| 551 | |
| 552 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 553 | ar = (AsyncResult) msg.obj; |
| 554 | request = (MainThreadRequest) ar.userObj; |
| 555 | if (ar.exception == null && ar.result != null) { |
| 556 | request.result = ar.result; |
| 557 | } else { |
| 558 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 559 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 561 | break; |
| 562 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 563 | case CMD_SEND_ENVELOPE: |
| 564 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 565 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 566 | if (uiccCard == null) { |
| 567 | loge("sendEnvelopeWithStatus: No UICC"); |
| 568 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 569 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 570 | } else { |
| 571 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 572 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 573 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 574 | break; |
| 575 | |
| 576 | case EVENT_SEND_ENVELOPE_DONE: |
| 577 | ar = (AsyncResult) msg.obj; |
| 578 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 579 | if (ar.exception == null && ar.result != null) { |
| 580 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 581 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 582 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 583 | if (ar.result == null) { |
| 584 | loge("sendEnvelopeWithStatus: Empty response"); |
| 585 | } else if (ar.exception instanceof CommandException) { |
| 586 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 587 | ar.exception); |
| 588 | } else { |
| 589 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 590 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 591 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 593 | break; |
| 594 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 595 | case CMD_OPEN_CHANNEL: |
| 596 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 597 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 598 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 599 | if (uiccCard == null) { |
| 600 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 601 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 602 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 603 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 604 | } else { |
| 605 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 606 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 607 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 608 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 609 | break; |
| 610 | |
| 611 | case EVENT_OPEN_CHANNEL_DONE: |
| 612 | ar = (AsyncResult) msg.obj; |
| 613 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 614 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 615 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 616 | int[] result = (int[]) ar.result; |
| 617 | int channelId = result[0]; |
| 618 | byte[] selectResponse = null; |
| 619 | if (result.length > 1) { |
| 620 | selectResponse = new byte[result.length - 1]; |
| 621 | for (int i = 1; i < result.length; ++i) { |
| 622 | selectResponse[i - 1] = (byte) result[i]; |
| 623 | } |
| 624 | } |
| 625 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 626 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | if (ar.result == null) { |
| 629 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 631 | if (ar.exception != null) { |
| 632 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 633 | } |
| 634 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 635 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 636 | if (ar.exception instanceof CommandException) { |
| 637 | CommandException.Error error = |
| 638 | ((CommandException) (ar.exception)).getCommandError(); |
| 639 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 640 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 641 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 642 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 646 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 648 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 649 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | break; |
| 651 | |
| 652 | case CMD_CLOSE_CHANNEL: |
| 653 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 654 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 655 | if (uiccCard == null) { |
| 656 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 657 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 658 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 659 | } else { |
| 660 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 661 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 662 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 666 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 667 | break; |
| 668 | |
| 669 | case CMD_NV_READ_ITEM: |
| 670 | request = (MainThreadRequest) msg.obj; |
| 671 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 672 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 673 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 674 | break; |
| 675 | |
| 676 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | ar = (AsyncResult) msg.obj; |
| 678 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 679 | if (ar.exception == null && ar.result != null) { |
| 680 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | request.result = ""; |
| 683 | if (ar.result == null) { |
| 684 | loge("nvReadItem: Empty response"); |
| 685 | } else if (ar.exception instanceof CommandException) { |
| 686 | loge("nvReadItem: CommandException: " + |
| 687 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 689 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 692 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 693 | break; |
| 694 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | case CMD_NV_WRITE_ITEM: |
| 696 | request = (MainThreadRequest) msg.obj; |
| 697 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 698 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 699 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 700 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case EVENT_NV_WRITE_ITEM_DONE: |
| 704 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 705 | break; |
| 706 | |
| 707 | case CMD_NV_WRITE_CDMA_PRL: |
| 708 | request = (MainThreadRequest) msg.obj; |
| 709 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 710 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 711 | break; |
| 712 | |
| 713 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 714 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 715 | break; |
| 716 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 717 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 719 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 720 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 721 | break; |
| 722 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 723 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 724 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 725 | break; |
| 726 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 727 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 728 | request = (MainThreadRequest) msg.obj; |
| 729 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 730 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 731 | break; |
| 732 | |
| 733 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 734 | ar = (AsyncResult) msg.obj; |
| 735 | request = (MainThreadRequest) ar.userObj; |
| 736 | if (ar.exception == null && ar.result != null) { |
| 737 | request.result = ar.result; // Integer |
| 738 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 739 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 740 | if (ar.result == null) { |
| 741 | loge("getPreferredNetworkType: Empty response"); |
| 742 | } else if (ar.exception instanceof CommandException) { |
| 743 | loge("getPreferredNetworkType: CommandException: " + |
| 744 | ar.exception); |
| 745 | } else { |
| 746 | loge("getPreferredNetworkType: Unknown exception"); |
| 747 | } |
| 748 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 749 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 753 | request = (MainThreadRequest) msg.obj; |
| 754 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 755 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 756 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 757 | break; |
| 758 | |
| 759 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 760 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 761 | break; |
| 762 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 763 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 764 | request = (MainThreadRequest)msg.obj; |
| 765 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 766 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 767 | break; |
| 768 | |
| 769 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 770 | ar = (AsyncResult)msg.obj; |
| 771 | request = (MainThreadRequest)ar.userObj; |
| 772 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 773 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 774 | break; |
| 775 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 776 | case CMD_SET_VOICEMAIL_NUMBER: |
| 777 | request = (MainThreadRequest) msg.obj; |
| 778 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 779 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 780 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 781 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 785 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 786 | break; |
| 787 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 788 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 789 | request = (MainThreadRequest) msg.obj; |
| 790 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 791 | request); |
| 792 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 793 | break; |
| 794 | |
| 795 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 796 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 797 | break; |
| 798 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 799 | case CMD_PERFORM_NETWORK_SCAN: |
| 800 | request = (MainThreadRequest) msg.obj; |
| 801 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 802 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 803 | break; |
| 804 | |
| 805 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 806 | ar = (AsyncResult) msg.obj; |
| 807 | request = (MainThreadRequest) ar.userObj; |
| 808 | CellNetworkScanResult cellScanResult; |
| 809 | if (ar.exception == null && ar.result != null) { |
| 810 | cellScanResult = new CellNetworkScanResult( |
| 811 | CellNetworkScanResult.STATUS_SUCCESS, |
| 812 | (List<OperatorInfo>) ar.result); |
| 813 | } else { |
| 814 | if (ar.result == null) { |
| 815 | loge("getCellNetworkScanResults: Empty response"); |
| 816 | } |
| 817 | if (ar.exception != null) { |
| 818 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 819 | } |
| 820 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 821 | if (ar.exception instanceof CommandException) { |
| 822 | CommandException.Error error = |
| 823 | ((CommandException) (ar.exception)).getCommandError(); |
| 824 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 825 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 826 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 827 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 828 | } |
| 829 | } |
| 830 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 831 | } |
| 832 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 833 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 834 | break; |
| 835 | |
| 836 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 837 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 838 | ManualNetworkSelectionArgument selArg = |
| 839 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 840 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 841 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 842 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 843 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 844 | break; |
| 845 | |
| 846 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 847 | ar = (AsyncResult) msg.obj; |
| 848 | request = (MainThreadRequest) ar.userObj; |
| 849 | if (ar.exception == null) { |
| 850 | request.result = true; |
| 851 | } else { |
| 852 | request.result = false; |
| 853 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 854 | } |
| 855 | notifyRequester(request); |
| 856 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 857 | break; |
| 858 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 859 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 860 | request = (MainThreadRequest) msg.obj; |
| 861 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 862 | if (defaultPhone != null) { |
| 863 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 864 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 865 | break; |
| 866 | |
| 867 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 868 | ar = (AsyncResult) msg.obj; |
| 869 | request = (MainThreadRequest) ar.userObj; |
| 870 | if (ar.exception == null && ar.result != null) { |
| 871 | request.result = ar.result; |
| 872 | } else { |
| 873 | if (ar.result == null) { |
| 874 | loge("queryModemActivityInfo: Empty response"); |
| 875 | } else if (ar.exception instanceof CommandException) { |
| 876 | loge("queryModemActivityInfo: CommandException: " + |
| 877 | ar.exception); |
| 878 | } else { |
| 879 | loge("queryModemActivityInfo: Unknown exception"); |
| 880 | } |
| 881 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 882 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 883 | if (request.result == null) { |
| 884 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 885 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 886 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 887 | break; |
| 888 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 889 | case CMD_SET_ALLOWED_CARRIERS: |
| 890 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 891 | CarrierRestrictionRules argument = |
| 892 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 893 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 894 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 895 | break; |
| 896 | |
| 897 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 898 | ar = (AsyncResult) msg.obj; |
| 899 | request = (MainThreadRequest) ar.userObj; |
| 900 | if (ar.exception == null && ar.result != null) { |
| 901 | request.result = ar.result; |
| 902 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 903 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 904 | if (ar.exception instanceof CommandException) { |
| 905 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 906 | CommandException.Error error = |
| 907 | ((CommandException) (ar.exception)).getCommandError(); |
| 908 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 909 | request.result = |
| 910 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 911 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 912 | } else { |
| 913 | loge("setAllowedCarriers: Unknown exception"); |
| 914 | } |
| 915 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 916 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case CMD_GET_ALLOWED_CARRIERS: |
| 920 | request = (MainThreadRequest) msg.obj; |
| 921 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 922 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 923 | break; |
| 924 | |
| 925 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 926 | ar = (AsyncResult) msg.obj; |
| 927 | request = (MainThreadRequest) ar.userObj; |
| 928 | if (ar.exception == null && ar.result != null) { |
| 929 | request.result = ar.result; |
| 930 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 931 | request.result = new IllegalStateException( |
| 932 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 933 | if (ar.result == null) { |
| 934 | loge("getAllowedCarriers: Empty response"); |
| 935 | } else if (ar.exception instanceof CommandException) { |
| 936 | loge("getAllowedCarriers: CommandException: " + |
| 937 | ar.exception); |
| 938 | } else { |
| 939 | loge("getAllowedCarriers: Unknown exception"); |
| 940 | } |
| 941 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 942 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 943 | break; |
| 944 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 945 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 946 | ar = (AsyncResult) msg.obj; |
| 947 | request = (MainThreadRequest) ar.userObj; |
| 948 | if (ar.exception == null && ar.result != null) { |
| 949 | request.result = ar.result; |
| 950 | } else { |
| 951 | request.result = new IllegalArgumentException( |
| 952 | "Failed to retrieve Forbidden Plmns"); |
| 953 | if (ar.result == null) { |
| 954 | loge("getForbiddenPlmns: Empty response"); |
| 955 | } else { |
| 956 | loge("getForbiddenPlmns: Unknown exception"); |
| 957 | } |
| 958 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 959 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 960 | break; |
| 961 | |
| 962 | case CMD_GET_FORBIDDEN_PLMNS: |
| 963 | request = (MainThreadRequest) msg.obj; |
| 964 | uiccCard = getUiccCardFromRequest(request); |
| 965 | if (uiccCard == null) { |
| 966 | loge("getForbiddenPlmns() UiccCard is null"); |
| 967 | request.result = new IllegalArgumentException( |
| 968 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 969 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 970 | break; |
| 971 | } |
| 972 | Integer appType = (Integer) request.argument; |
| 973 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 974 | if (uiccApp == null) { |
| 975 | loge("getForbiddenPlmns() no app with specified type -- " |
| 976 | + appType); |
| 977 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 978 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 979 | break; |
| 980 | } else { |
| 981 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 982 | + " specified type -- " + appType); |
| 983 | } |
| 984 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 985 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 986 | onCompleted); |
| 987 | break; |
| 988 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 989 | case CMD_SWITCH_SLOTS: |
| 990 | request = (MainThreadRequest) msg.obj; |
| 991 | int[] physicalSlots = (int[]) request.argument; |
| 992 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 993 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 994 | break; |
| 995 | |
| 996 | case EVENT_SWITCH_SLOTS_DONE: |
| 997 | ar = (AsyncResult) msg.obj; |
| 998 | request = (MainThreadRequest) ar.userObj; |
| 999 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1000 | notifyRequester(request); |
| 1001 | break; |
| 1002 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1003 | request = (MainThreadRequest) msg.obj; |
| 1004 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1005 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1006 | break; |
| 1007 | |
| 1008 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1009 | ar = (AsyncResult) msg.obj; |
| 1010 | request = (MainThreadRequest) ar.userObj; |
| 1011 | if (ar.exception != null) { |
| 1012 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1013 | } else { |
| 1014 | int mode = ((int[]) ar.result)[0]; |
| 1015 | if (mode == 0) { |
| 1016 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1017 | } else { |
| 1018 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1019 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1020 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1021 | notifyRequester(request); |
| 1022 | break; |
| 1023 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1024 | request = (MainThreadRequest) msg.obj; |
| 1025 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1026 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1027 | break; |
| 1028 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1029 | ar = (AsyncResult) msg.obj; |
| 1030 | request = (MainThreadRequest) ar.userObj; |
| 1031 | if (ar.exception != null) { |
| 1032 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1033 | } else { |
| 1034 | request.result = ((int[]) ar.result)[0]; |
| 1035 | } |
| 1036 | notifyRequester(request); |
| 1037 | break; |
| 1038 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1039 | request = (MainThreadRequest) msg.obj; |
| 1040 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1041 | int mode = (int) request.argument; |
| 1042 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1043 | break; |
| 1044 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1045 | ar = (AsyncResult) msg.obj; |
| 1046 | request = (MainThreadRequest) ar.userObj; |
| 1047 | request.result = ar.exception == null; |
| 1048 | notifyRequester(request); |
| 1049 | break; |
| 1050 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1051 | request = (MainThreadRequest) msg.obj; |
| 1052 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1053 | int subscriptionMode = (int) request.argument; |
| 1054 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1055 | break; |
| 1056 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1057 | ar = (AsyncResult) msg.obj; |
| 1058 | request = (MainThreadRequest) ar.userObj; |
| 1059 | request.result = ar.exception == null; |
| 1060 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1061 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1062 | case CMD_GET_ALL_CELL_INFO: |
| 1063 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1064 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1065 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1066 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1067 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1068 | ar = (AsyncResult) msg.obj; |
| 1069 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1070 | // If a timeout occurs, the response will be null |
| 1071 | request.result = (ar.exception == null && ar.result != null) |
| 1072 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1073 | synchronized (request) { |
| 1074 | request.notifyAll(); |
| 1075 | } |
| 1076 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1077 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1078 | request = (MainThreadRequest) msg.obj; |
| 1079 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1080 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1081 | break; |
| 1082 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1083 | ar = (AsyncResult) msg.obj; |
| 1084 | request = (MainThreadRequest) ar.userObj; |
| 1085 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1086 | try { |
| 1087 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1088 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1089 | cb.onError( |
| 1090 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1091 | ar.exception.getClass().getName(), |
| 1092 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1093 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1094 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1095 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1096 | } else { |
| 1097 | // use the result as returned |
| 1098 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1099 | } |
| 1100 | } catch (RemoteException re) { |
| 1101 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1102 | } |
| 1103 | break; |
| 1104 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1105 | request = (MainThreadRequest) msg.obj; |
| 1106 | WorkSource ws = (WorkSource) request.argument; |
| 1107 | Phone phone = getPhoneFromRequest(request); |
| 1108 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1109 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1110 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1111 | ar = (AsyncResult) msg.obj; |
| 1112 | request = (MainThreadRequest) ar.userObj; |
| 1113 | if (ar.exception == null) { |
| 1114 | request.result = ar.result; |
| 1115 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1116 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1117 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1118 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1119 | } |
| 1120 | |
| 1121 | synchronized (request) { |
| 1122 | request.notifyAll(); |
| 1123 | } |
| 1124 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1125 | case CMD_MODEM_REBOOT: |
| 1126 | request = (MainThreadRequest) msg.obj; |
| 1127 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1128 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1129 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1130 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1131 | handleNullReturnEvent(msg, "rebootModem"); |
| 1132 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1133 | case CMD_REQUEST_ENABLE_MODEM: |
| 1134 | request = (MainThreadRequest) msg.obj; |
| 1135 | boolean enable = (boolean) request.argument; |
| 1136 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1137 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1138 | PhoneConfigurationManager.getInstance() |
| 1139 | .enablePhone(request.phone, enable, onCompleted); |
| 1140 | break; |
| 1141 | case EVENT_ENABLE_MODEM_DONE: |
| 1142 | ar = (AsyncResult) msg.obj; |
| 1143 | request = (MainThreadRequest) ar.userObj; |
| 1144 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1145 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1146 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1147 | if ((boolean) request.result) { |
| 1148 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1149 | updateModemStateMetrics(); |
| 1150 | } else { |
| 1151 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1152 | + ar.exception); |
| 1153 | } |
| 1154 | notifyRequester(request); |
| 1155 | break; |
| 1156 | case CMD_GET_MODEM_STATUS: |
| 1157 | request = (MainThreadRequest) msg.obj; |
| 1158 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1159 | PhoneConfigurationManager.getInstance() |
| 1160 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1161 | break; |
| 1162 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1163 | ar = (AsyncResult) msg.obj; |
| 1164 | request = (MainThreadRequest) ar.userObj; |
| 1165 | int id = request.phone.getPhoneId(); |
| 1166 | if (ar.exception == null && ar.result != null) { |
| 1167 | request.result = ar.result; |
| 1168 | //update the cache as modem status has changed |
| 1169 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1170 | (boolean) request.result); |
| 1171 | } else { |
| 1172 | // Return true if modem status cannot be retrieved. For most cases, |
| 1173 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1174 | // and disable modem are not supported. Modem is always on. |
| 1175 | // TODO: this should be fixed in R to support a third |
| 1176 | // status UNKNOWN b/131631629 |
| 1177 | request.result = true; |
| 1178 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1179 | + ar.exception); |
| 1180 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1181 | notifyRequester(request); |
| 1182 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1183 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1184 | ar = (AsyncResult) msg.obj; |
| 1185 | request = (MainThreadRequest) ar.userObj; |
| 1186 | if (ar.exception == null && ar.result != null) { |
| 1187 | request.result = ar.result; |
| 1188 | } else { |
| 1189 | request.result = -1; |
| 1190 | loge("Failed to set Forbidden Plmns"); |
| 1191 | if (ar.result == null) { |
| 1192 | loge("setForbidenPlmns: Empty response"); |
| 1193 | } else if (ar.exception != null) { |
| 1194 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1195 | request.result = -1; |
| 1196 | } else { |
| 1197 | loge("setForbiddenPlmns: Unknown exception"); |
| 1198 | } |
| 1199 | } |
| 1200 | notifyRequester(request); |
| 1201 | break; |
| 1202 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1203 | request = (MainThreadRequest) msg.obj; |
| 1204 | uiccCard = getUiccCardFromRequest(request); |
| 1205 | if (uiccCard == null) { |
| 1206 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1207 | request.result = -1; |
| 1208 | notifyRequester(request); |
| 1209 | break; |
| 1210 | } |
| 1211 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1212 | (Pair<Integer, List<String>>) request.argument; |
| 1213 | appType = setFplmnsArgs.first; |
| 1214 | List<String> fplmns = setFplmnsArgs.second; |
| 1215 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1216 | if (uiccApp == null) { |
| 1217 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1218 | request.result = -1; |
| 1219 | loge("Failed to get UICC App"); |
| 1220 | notifyRequester(request); |
| 1221 | } else { |
| 1222 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1223 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1224 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1225 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1226 | case CMD_ERASE_MODEM_CONFIG: |
| 1227 | request = (MainThreadRequest) msg.obj; |
| 1228 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1229 | defaultPhone.eraseModemConfig(onCompleted); |
| 1230 | break; |
| 1231 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1232 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1233 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1234 | default: |
| 1235 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1236 | break; |
| 1237 | } |
| 1238 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1239 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1240 | private void notifyRequester(MainThreadRequest request) { |
| 1241 | synchronized (request) { |
| 1242 | request.notifyAll(); |
| 1243 | } |
| 1244 | } |
| 1245 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1246 | private void handleNullReturnEvent(Message msg, String command) { |
| 1247 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1248 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1249 | if (ar.exception == null) { |
| 1250 | request.result = true; |
| 1251 | } else { |
| 1252 | request.result = false; |
| 1253 | if (ar.exception instanceof CommandException) { |
| 1254 | loge(command + ": CommandException: " + ar.exception); |
| 1255 | } else { |
| 1256 | loge(command + ": Unknown exception"); |
| 1257 | } |
| 1258 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1259 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1260 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * Posts the specified command to be executed on the main thread, |
| 1265 | * waits for the request to complete, and returns the result. |
| 1266 | * @see #sendRequestAsync |
| 1267 | */ |
| 1268 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1269 | return sendRequest( |
| 1270 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * Posts the specified command to be executed on the main thread, |
| 1275 | * waits for the request to complete, and returns the result. |
| 1276 | * @see #sendRequestAsync |
| 1277 | */ |
| 1278 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1279 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1280 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * Posts the specified command to be executed on the main thread, |
| 1285 | * waits for the request to complete, and returns the result. |
| 1286 | * @see #sendRequestAsync |
| 1287 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1288 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1289 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Posts the specified command to be executed on the main thread, |
| 1294 | * waits for the request to complete, and returns the result. |
| 1295 | * @see #sendRequestAsync |
| 1296 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1297 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1298 | return sendRequest(command, argument, subId, null, workSource); |
| 1299 | } |
| 1300 | |
| 1301 | /** |
| 1302 | * Posts the specified command to be executed on the main thread, |
| 1303 | * waits for the request to complete, and returns the result. |
| 1304 | * @see #sendRequestAsync |
| 1305 | */ |
| 1306 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1307 | return sendRequest( |
| 1308 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1309 | } |
| 1310 | |
| 1311 | /** |
| 1312 | * Posts the specified command to be executed on the main thread, |
| 1313 | * waits for the request to complete, and returns the result. |
| 1314 | * @see #sendRequestAsync |
| 1315 | */ |
| 1316 | private Object sendRequest( |
| 1317 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1318 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1319 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1320 | } |
| 1321 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1322 | MainThreadRequest request = null; |
| 1323 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1324 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1325 | } else if (phone != null) { |
| 1326 | request = new MainThreadRequest(argument, phone, workSource); |
| 1327 | } else { |
| 1328 | request = new MainThreadRequest(argument, subId, workSource); |
| 1329 | } |
| 1330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1331 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1332 | msg.sendToTarget(); |
| 1333 | |
| 1334 | // Wait for the request to complete |
| 1335 | synchronized (request) { |
| 1336 | while (request.result == null) { |
| 1337 | try { |
| 1338 | request.wait(); |
| 1339 | } catch (InterruptedException e) { |
| 1340 | // Do nothing, go back and wait until the request is complete |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | return request.result; |
| 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1349 | * Posts the specified command to be executed on the main thread, and |
| 1350 | * returns immediately. |
| 1351 | * @see #sendRequest |
| 1352 | */ |
| 1353 | private void sendRequestAsync(int command) { |
| 1354 | mMainThreadHandler.sendEmptyMessage(command); |
| 1355 | } |
| 1356 | |
| 1357 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1358 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1359 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1360 | */ |
| 1361 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1362 | sendRequestAsync(command, argument, null, null); |
| 1363 | } |
| 1364 | |
| 1365 | /** |
| 1366 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1367 | * @see {@link #sendRequest(int,Object)} |
| 1368 | */ |
| 1369 | private void sendRequestAsync( |
| 1370 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1371 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1372 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1373 | msg.sendToTarget(); |
| 1374 | } |
| 1375 | |
| 1376 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1377 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1378 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1379 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1380 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1381 | synchronized (PhoneInterfaceManager.class) { |
| 1382 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1383 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1384 | } else { |
| 1385 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1386 | } |
| 1387 | return sInstance; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1392 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1393 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1394 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1395 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1396 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1397 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1398 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1399 | mTelephonySharedPreferences = |
| 1400 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1401 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1402 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1403 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1404 | publish(); |
| 1405 | } |
| 1406 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1407 | private Phone getDefaultPhone() { |
| 1408 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1409 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1410 | } |
| 1411 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1412 | private void publish() { |
| 1413 | if (DBG) log("publish: " + this); |
| 1414 | |
| 1415 | ServiceManager.addService("phone", this); |
| 1416 | } |
| 1417 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1418 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1419 | if (request.phone != null) { |
| 1420 | return request.phone; |
| 1421 | } else { |
| 1422 | return getPhoneFromSubId(request.subId); |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | private Phone getPhoneFromSubId(int subId) { |
| 1427 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1428 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1429 | } |
| 1430 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1431 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1432 | Phone phone = getPhoneFromRequest(request); |
| 1433 | return phone == null ? null : |
| 1434 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1435 | } |
| 1436 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1437 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1438 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1439 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1440 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1441 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1442 | private void sendEraseModemConfig(Phone phone) { |
| 1443 | if (phone != null) { |
| 1444 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1445 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1446 | final long identity = Binder.clearCallingIdentity(); |
| 1447 | try { |
| 1448 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1449 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1450 | } finally { |
| 1451 | Binder.restoreCallingIdentity(identity); |
| 1452 | } |
| 1453 | } |
| 1454 | } |
| 1455 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1456 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1457 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1460 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1461 | if (DBG) log("dial: " + number); |
| 1462 | // No permission check needed here: This is just a wrapper around the |
| 1463 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1464 | // the UI before it does anything. |
| 1465 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1466 | final long identity = Binder.clearCallingIdentity(); |
| 1467 | try { |
| 1468 | String url = createTelUrl(number); |
| 1469 | if (url == null) { |
| 1470 | return; |
| 1471 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1472 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1473 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1474 | PhoneConstants.State state = mCM.getState(subId); |
| 1475 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1476 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1477 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1478 | mApp.startActivity(intent); |
| 1479 | } |
| 1480 | } finally { |
| 1481 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1486 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1489 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1490 | if (DBG) log("call: " + number); |
| 1491 | |
| 1492 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1493 | // need to do a permission check since we're calling startActivity() |
| 1494 | // from the context of the phone app. |
| 1495 | enforceCallPermission(); |
| 1496 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1497 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1498 | != AppOpsManager.MODE_ALLOWED) { |
| 1499 | return; |
| 1500 | } |
| 1501 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1502 | final long identity = Binder.clearCallingIdentity(); |
| 1503 | try { |
| 1504 | String url = createTelUrl(number); |
| 1505 | if (url == null) { |
| 1506 | return; |
| 1507 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1508 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1509 | boolean isValid = false; |
| 1510 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1511 | if (slist != null) { |
| 1512 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1513 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1514 | isValid = true; |
| 1515 | break; |
| 1516 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1517 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1518 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1519 | if (!isValid) { |
| 1520 | return; |
| 1521 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1522 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1523 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1524 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1525 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1526 | mApp.startActivity(intent); |
| 1527 | } finally { |
| 1528 | Binder.restoreCallingIdentity(identity); |
| 1529 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1532 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1533 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1536 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1537 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1538 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1539 | } |
| 1540 | |
| 1541 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1542 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1545 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1546 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1547 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1548 | } |
| 1549 | |
| 1550 | /** {@hide} */ |
| 1551 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1552 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1555 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1556 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1557 | |
| 1558 | final long identity = Binder.clearCallingIdentity(); |
| 1559 | try { |
| 1560 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1561 | checkSimPin.start(); |
| 1562 | return checkSimPin.unlockSim(null, pin); |
| 1563 | } finally { |
| 1564 | Binder.restoreCallingIdentity(identity); |
| 1565 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1568 | /** {@hide} */ |
| 1569 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1570 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1573 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1574 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1575 | |
| 1576 | final long identity = Binder.clearCallingIdentity(); |
| 1577 | try { |
| 1578 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1579 | checkSimPuk.start(); |
| 1580 | return checkSimPuk.unlockSim(puk, pin); |
| 1581 | } finally { |
| 1582 | Binder.restoreCallingIdentity(identity); |
| 1583 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1587 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1588 | * a synchronous one. |
| 1589 | */ |
| 1590 | private static class UnlockSim extends Thread { |
| 1591 | |
| 1592 | private final IccCard mSimCard; |
| 1593 | |
| 1594 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1595 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1596 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1597 | |
| 1598 | // For replies from SimCard interface |
| 1599 | private Handler mHandler; |
| 1600 | |
| 1601 | // For async handler to identify request type |
| 1602 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1603 | |
| 1604 | public UnlockSim(IccCard simCard) { |
| 1605 | mSimCard = simCard; |
| 1606 | } |
| 1607 | |
| 1608 | @Override |
| 1609 | public void run() { |
| 1610 | Looper.prepare(); |
| 1611 | synchronized (UnlockSim.this) { |
| 1612 | mHandler = new Handler() { |
| 1613 | @Override |
| 1614 | public void handleMessage(Message msg) { |
| 1615 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1616 | switch (msg.what) { |
| 1617 | case SUPPLY_PIN_COMPLETE: |
| 1618 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1619 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1620 | mRetryCount = msg.arg1; |
| 1621 | if (ar.exception != null) { |
| 1622 | if (ar.exception instanceof CommandException && |
| 1623 | ((CommandException)(ar.exception)).getCommandError() |
| 1624 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1625 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1626 | } else { |
| 1627 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1628 | } |
| 1629 | } else { |
| 1630 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1631 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1632 | mDone = true; |
| 1633 | UnlockSim.this.notifyAll(); |
| 1634 | } |
| 1635 | break; |
| 1636 | } |
| 1637 | } |
| 1638 | }; |
| 1639 | UnlockSim.this.notifyAll(); |
| 1640 | } |
| 1641 | Looper.loop(); |
| 1642 | } |
| 1643 | |
| 1644 | /* |
| 1645 | * Use PIN or PUK to unlock SIM card |
| 1646 | * |
| 1647 | * If PUK is null, unlock SIM card with PIN |
| 1648 | * |
| 1649 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1650 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1651 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1652 | |
| 1653 | while (mHandler == null) { |
| 1654 | try { |
| 1655 | wait(); |
| 1656 | } catch (InterruptedException e) { |
| 1657 | Thread.currentThread().interrupt(); |
| 1658 | } |
| 1659 | } |
| 1660 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1661 | |
| 1662 | if (puk == null) { |
| 1663 | mSimCard.supplyPin(pin, callback); |
| 1664 | } else { |
| 1665 | mSimCard.supplyPuk(puk, pin, callback); |
| 1666 | } |
| 1667 | |
| 1668 | while (!mDone) { |
| 1669 | try { |
| 1670 | Log.d(LOG_TAG, "wait for done"); |
| 1671 | wait(); |
| 1672 | } catch (InterruptedException e) { |
| 1673 | // Restore the interrupted status |
| 1674 | Thread.currentThread().interrupt(); |
| 1675 | } |
| 1676 | } |
| 1677 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1678 | int[] resultArray = new int[2]; |
| 1679 | resultArray[0] = mResult; |
| 1680 | resultArray[1] = mRetryCount; |
| 1681 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1686 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1687 | |
| 1688 | } |
| 1689 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1690 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | // No permission check needed here: this call is harmless, and it's |
| 1692 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1693 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1694 | final long identity = Binder.clearCallingIdentity(); |
| 1695 | try { |
| 1696 | final Phone phone = getPhone(subId); |
| 1697 | if (phone != null) { |
| 1698 | phone.updateServiceLocation(); |
| 1699 | } |
| 1700 | } finally { |
| 1701 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1702 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1705 | @Override |
| 1706 | public boolean isRadioOn(String callingPackage) { |
| 1707 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1710 | @Override |
| 1711 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1712 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1713 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1714 | return false; |
| 1715 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1716 | |
| 1717 | final long identity = Binder.clearCallingIdentity(); |
| 1718 | try { |
| 1719 | return isRadioOnForSubscriber(subId); |
| 1720 | } finally { |
| 1721 | Binder.restoreCallingIdentity(identity); |
| 1722 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1726 | final long identity = Binder.clearCallingIdentity(); |
| 1727 | try { |
| 1728 | final Phone phone = getPhone(subId); |
| 1729 | if (phone != null) { |
| 1730 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1731 | } else { |
| 1732 | return false; |
| 1733 | } |
| 1734 | } finally { |
| 1735 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1736 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1740 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1741 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1742 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1743 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1744 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1745 | |
| 1746 | final long identity = Binder.clearCallingIdentity(); |
| 1747 | try { |
| 1748 | final Phone phone = getPhone(subId); |
| 1749 | if (phone != null) { |
| 1750 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1751 | } |
| 1752 | } finally { |
| 1753 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1754 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1758 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1761 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1762 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1763 | |
| 1764 | final long identity = Binder.clearCallingIdentity(); |
| 1765 | try { |
| 1766 | final Phone phone = getPhone(subId); |
| 1767 | if (phone == null) { |
| 1768 | return false; |
| 1769 | } |
| 1770 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1771 | toggleRadioOnOffForSubscriber(subId); |
| 1772 | } |
| 1773 | return true; |
| 1774 | } finally { |
| 1775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1777 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1778 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1779 | public boolean needMobileRadioShutdown() { |
| 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 |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2034 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 2035 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2036 | // registered cell info, so return a NULL country instead. |
| 2037 | final long identity = Binder.clearCallingIdentity(); |
| 2038 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2039 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2040 | // Get default phone in this case. |
| 2041 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2042 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2043 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2044 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2045 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2046 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 2047 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 2048 | return ""; |
| 2049 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2050 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2051 | if (phone != null) { |
| 2052 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2053 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2054 | if (sst != null) { |
| 2055 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2056 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2057 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2058 | return lt.getCurrentCountry(); |
| 2059 | } else if (emergencyNumberTracker != null) { |
| 2060 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2061 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | } |
| 2065 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2066 | } finally { |
| 2067 | Binder.restoreCallingIdentity(identity); |
| 2068 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2072 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2073 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2076 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2077 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2078 | mApp.enforceCallingOrSelfPermission( |
| 2079 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2080 | |
| 2081 | final long identity = Binder.clearCallingIdentity(); |
| 2082 | try { |
| 2083 | final Phone phone = getPhone(subId); |
| 2084 | if (phone != null) { |
| 2085 | phone.enableLocationUpdates(); |
| 2086 | } |
| 2087 | } finally { |
| 2088 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2089 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | @Override |
| 2093 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2094 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2097 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2098 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | mApp.enforceCallingOrSelfPermission( |
| 2100 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2101 | |
| 2102 | final long identity = Binder.clearCallingIdentity(); |
| 2103 | try { |
| 2104 | final Phone phone = getPhone(subId); |
| 2105 | if (phone != null) { |
| 2106 | phone.disableLocationUpdates(); |
| 2107 | } |
| 2108 | } finally { |
| 2109 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2110 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2113 | /** |
| 2114 | * Returns the target SDK version number for a given package name. |
| 2115 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2116 | * This call MUST be invoked before clearing the calling UID. |
| 2117 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2118 | * @return target SDK if the package is found or INT_MAX. |
| 2119 | */ |
| 2120 | private int getTargetSdk(String packageName) { |
| 2121 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2122 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2123 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2124 | if (ai != null) return ai.targetSdkVersion; |
| 2125 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2126 | loge("Failed to get package info for pkg=" |
| 2127 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2128 | } |
| 2129 | return Integer.MAX_VALUE; |
| 2130 | } |
| 2131 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2132 | @Override |
| 2133 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2134 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2135 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2136 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2137 | throw new SecurityException( |
| 2138 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2139 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2140 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2141 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2142 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2143 | return null; |
| 2144 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2145 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2146 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2147 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2148 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2149 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2150 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2151 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2152 | for (CellInfo ci : info) { |
| 2153 | if (ci instanceof CellInfoGsm) { |
| 2154 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2155 | } else if (ci instanceof CellInfoWcdma) { |
| 2156 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2157 | } |
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 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2162 | private List<CellInfo> getCachedCellInfo() { |
| 2163 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2164 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2165 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2166 | if (info != null) cellInfos.addAll(info); |
| 2167 | } |
| 2168 | return cellInfos; |
| 2169 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | |
| 2171 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2172 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2173 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2174 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2175 | |
| 2176 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2177 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2178 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2179 | .setCallingPackage(callingPackage) |
| 2180 | .setCallingPid(Binder.getCallingPid()) |
| 2181 | .setCallingUid(Binder.getCallingUid()) |
| 2182 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2183 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2184 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2185 | .build()); |
| 2186 | switch (locationResult) { |
| 2187 | case DENIED_HARD: |
| 2188 | throw new SecurityException("Not allowed to access cell info"); |
| 2189 | case DENIED_SOFT: |
| 2190 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2193 | final int targetSdk = getTargetSdk(callingPackage); |
| 2194 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2195 | return getCachedCellInfo(); |
| 2196 | } |
| 2197 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2198 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2199 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2200 | final long identity = Binder.clearCallingIdentity(); |
| 2201 | try { |
| 2202 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2203 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2204 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2205 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2206 | if (info != null) cellInfos.addAll(info); |
| 2207 | } |
| 2208 | return cellInfos; |
| 2209 | } finally { |
| 2210 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2211 | } |
| 2212 | } |
| 2213 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2214 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2215 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2216 | requestCellInfoUpdateInternal( |
| 2217 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2218 | } |
| 2219 | |
| 2220 | @Override |
| 2221 | public void requestCellInfoUpdateWithWorkSource( |
| 2222 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2223 | enforceModifyPermission(); |
| 2224 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2225 | } |
| 2226 | |
| 2227 | private void requestCellInfoUpdateInternal( |
| 2228 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2229 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2230 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2231 | |
| 2232 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2233 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2234 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2235 | .setCallingPackage(callingPackage) |
| 2236 | .setCallingPid(Binder.getCallingPid()) |
| 2237 | .setCallingUid(Binder.getCallingUid()) |
| 2238 | .setMethod("requestCellInfoUpdate") |
| 2239 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2240 | .build()); |
| 2241 | switch (locationResult) { |
| 2242 | case DENIED_HARD: |
| 2243 | throw new SecurityException("Not allowed to access cell info"); |
| 2244 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2245 | try { |
| 2246 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2247 | } catch (RemoteException re) { |
| 2248 | // Drop without consequences |
| 2249 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2250 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2253 | |
| 2254 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2255 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2256 | |
| 2257 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2258 | } |
| 2259 | |
| 2260 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2262 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2263 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | |
| 2265 | final long identity = Binder.clearCallingIdentity(); |
| 2266 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2267 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2268 | } finally { |
| 2269 | Binder.restoreCallingIdentity(identity); |
| 2270 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2273 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2274 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2275 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2276 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2277 | return null; |
| 2278 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2279 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2280 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2281 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2282 | return null; |
| 2283 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2284 | |
| 2285 | final long identity = Binder.clearCallingIdentity(); |
| 2286 | try { |
| 2287 | return phone.getImei(); |
| 2288 | } finally { |
| 2289 | Binder.restoreCallingIdentity(identity); |
| 2290 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2294 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2295 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2296 | String tac = null; |
| 2297 | if (phone != null) { |
| 2298 | String imei = phone.getImei(); |
| 2299 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2300 | } |
| 2301 | return tac; |
| 2302 | } |
| 2303 | |
| 2304 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2305 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2306 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2307 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2308 | return null; |
| 2309 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2310 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2311 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2312 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2313 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2314 | return null; |
| 2315 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2316 | |
| 2317 | final long identity = Binder.clearCallingIdentity(); |
| 2318 | try { |
| 2319 | return phone.getMeid(); |
| 2320 | } finally { |
| 2321 | Binder.restoreCallingIdentity(identity); |
| 2322 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2326 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2327 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2328 | String manufacturerCode = null; |
| 2329 | if (phone != null) { |
| 2330 | String meid = phone.getMeid(); |
| 2331 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2332 | } |
| 2333 | return manufacturerCode; |
| 2334 | } |
| 2335 | |
| 2336 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2337 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2338 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2339 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2340 | return null; |
| 2341 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2342 | int subId = phone.getSubId(); |
| 2343 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2344 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2345 | return null; |
| 2346 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2347 | |
| 2348 | final long identity = Binder.clearCallingIdentity(); |
| 2349 | try { |
| 2350 | return phone.getDeviceSvn(); |
| 2351 | } finally { |
| 2352 | Binder.restoreCallingIdentity(identity); |
| 2353 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2356 | @Override |
| 2357 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2358 | final long identity = Binder.clearCallingIdentity(); |
| 2359 | try { |
| 2360 | final Phone phone = getPhone(subId); |
| 2361 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2362 | } finally { |
| 2363 | Binder.restoreCallingIdentity(identity); |
| 2364 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | @Override |
| 2368 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2369 | final long identity = Binder.clearCallingIdentity(); |
| 2370 | try { |
| 2371 | final Phone phone = getPhone(subId); |
| 2372 | return phone == null ? null : phone.getCarrierName(); |
| 2373 | } finally { |
| 2374 | Binder.restoreCallingIdentity(identity); |
| 2375 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2376 | } |
| 2377 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2378 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2379 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2380 | final long identity = Binder.clearCallingIdentity(); |
| 2381 | try { |
| 2382 | final Phone phone = getPhone(subId); |
| 2383 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2384 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2385 | } finally { |
| 2386 | Binder.restoreCallingIdentity(identity); |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2391 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2392 | final long identity = Binder.clearCallingIdentity(); |
| 2393 | try { |
| 2394 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2395 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2396 | } finally { |
| 2397 | Binder.restoreCallingIdentity(identity); |
| 2398 | } |
| 2399 | } |
| 2400 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2401 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2402 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2403 | if (!isSubscriptionMccMnc) { |
| 2404 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2405 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2406 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2407 | if (phone == null) { |
| 2408 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2409 | } |
| 2410 | final long identity = Binder.clearCallingIdentity(); |
| 2411 | try { |
| 2412 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2413 | } finally { |
| 2414 | Binder.restoreCallingIdentity(identity); |
| 2415 | } |
| 2416 | } |
| 2417 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2418 | // |
| 2419 | // Internal helper methods. |
| 2420 | // |
| 2421 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2422 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2424 | * |
| 2425 | * @throws SecurityException if the caller does not have the required permission |
| 2426 | */ |
| 2427 | private void enforceModifyPermission() { |
| 2428 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2429 | } |
| 2430 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2431 | private void enforceActiveEmergencySessionPermission() { |
| 2432 | mApp.enforceCallingOrSelfPermission( |
| 2433 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2434 | } |
| 2435 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | /** |
| 2437 | * Make sure the caller has the CALL_PHONE permission. |
| 2438 | * |
| 2439 | * @throws SecurityException if the caller does not have the required permission |
| 2440 | */ |
| 2441 | private void enforceCallPermission() { |
| 2442 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2443 | } |
| 2444 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2445 | private void enforceSettingsPermission() { |
| 2446 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2449 | private String createTelUrl(String number) { |
| 2450 | if (TextUtils.isEmpty(number)) { |
| 2451 | return null; |
| 2452 | } |
| 2453 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2454 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2457 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2459 | } |
| 2460 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2461 | private static void logv(String msg) { |
| 2462 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2463 | } |
| 2464 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2465 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2467 | } |
| 2468 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2469 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2471 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2474 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2475 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2476 | final long identity = Binder.clearCallingIdentity(); |
| 2477 | try { |
| 2478 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2479 | if (phone == null) { |
| 2480 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2481 | } else { |
| 2482 | return phone.getPhoneType(); |
| 2483 | } |
| 2484 | } finally { |
| 2485 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2486 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | /** |
| 2490 | * Returns the CDMA ERI icon index to display |
| 2491 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2492 | @Override |
| 2493 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2494 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2497 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2498 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2499 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2500 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2501 | return -1; |
| 2502 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2503 | |
| 2504 | final long identity = Binder.clearCallingIdentity(); |
| 2505 | try { |
| 2506 | final Phone phone = getPhone(subId); |
| 2507 | if (phone != null) { |
| 2508 | return phone.getCdmaEriIconIndex(); |
| 2509 | } else { |
| 2510 | return -1; |
| 2511 | } |
| 2512 | } finally { |
| 2513 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2514 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | /** |
| 2518 | * Returns the CDMA ERI icon mode, |
| 2519 | * 0 - ON |
| 2520 | * 1 - FLASHING |
| 2521 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2522 | @Override |
| 2523 | public int getCdmaEriIconMode(String callingPackage) { |
| 2524 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2527 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2528 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2529 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2530 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2531 | return -1; |
| 2532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2533 | |
| 2534 | final long identity = Binder.clearCallingIdentity(); |
| 2535 | try { |
| 2536 | final Phone phone = getPhone(subId); |
| 2537 | if (phone != null) { |
| 2538 | return phone.getCdmaEriIconMode(); |
| 2539 | } else { |
| 2540 | return -1; |
| 2541 | } |
| 2542 | } finally { |
| 2543 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2544 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | /** |
| 2548 | * Returns the CDMA ERI text, |
| 2549 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2550 | @Override |
| 2551 | public String getCdmaEriText(String callingPackage) { |
| 2552 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2555 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2556 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2557 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2558 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2559 | return null; |
| 2560 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2561 | |
| 2562 | final long identity = Binder.clearCallingIdentity(); |
| 2563 | try { |
| 2564 | final Phone phone = getPhone(subId); |
| 2565 | if (phone != null) { |
| 2566 | return phone.getCdmaEriText(); |
| 2567 | } else { |
| 2568 | return null; |
| 2569 | } |
| 2570 | } finally { |
| 2571 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2572 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2576 | * Returns the CDMA MDN. |
| 2577 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2578 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2579 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2581 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | |
| 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
| 2585 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2586 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | return phone.getLine1Number(); |
| 2588 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2589 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | return null; |
| 2591 | } |
| 2592 | } finally { |
| 2593 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | /** |
| 2598 | * Returns the CDMA MIN. |
| 2599 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2600 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2601 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2603 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | |
| 2605 | final long identity = Binder.clearCallingIdentity(); |
| 2606 | try { |
| 2607 | final Phone phone = getPhone(subId); |
| 2608 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2609 | return phone.getCdmaMin(); |
| 2610 | } else { |
| 2611 | return null; |
| 2612 | } |
| 2613 | } finally { |
| 2614 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2615 | } |
| 2616 | } |
| 2617 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2618 | @Override |
| 2619 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2620 | INumberVerificationCallback callback, String callingPackage) { |
| 2621 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2622 | != PERMISSION_GRANTED) { |
| 2623 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2624 | } |
| 2625 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2626 | |
| 2627 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2628 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2629 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2630 | } |
| 2631 | |
| 2632 | if (range == null) { |
| 2633 | throw new NullPointerException("Range must be non-null"); |
| 2634 | } |
| 2635 | |
| 2636 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2637 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2638 | |
| 2639 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2640 | } |
| 2641 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2642 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2643 | * Returns true if CDMA provisioning needs to run. |
| 2644 | */ |
| 2645 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | final long identity = Binder.clearCallingIdentity(); |
| 2647 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2648 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2649 | } finally { |
| 2650 | Binder.restoreCallingIdentity(identity); |
| 2651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2655 | * Sets the voice mail number of a given subId. |
| 2656 | */ |
| 2657 | @Override |
| 2658 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2659 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | |
| 2661 | final long identity = Binder.clearCallingIdentity(); |
| 2662 | try { |
| 2663 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2664 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2665 | return success; |
| 2666 | } finally { |
| 2667 | Binder.restoreCallingIdentity(identity); |
| 2668 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2669 | } |
| 2670 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2671 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2672 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2673 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2674 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2675 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2676 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2677 | throw new SecurityException("caller must be system dialer"); |
| 2678 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | |
| 2680 | final long identity = Binder.clearCallingIdentity(); |
| 2681 | try { |
| 2682 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2683 | if (phoneAccountHandle == null) { |
| 2684 | return null; |
| 2685 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2686 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | } finally { |
| 2688 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2689 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2693 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2694 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2695 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2696 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2697 | return null; |
| 2698 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2699 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2700 | final long identity = Binder.clearCallingIdentity(); |
| 2701 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2702 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2703 | } finally { |
| 2704 | Binder.restoreCallingIdentity(identity); |
| 2705 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2709 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2710 | VisualVoicemailSmsFilterSettings settings) { |
| 2711 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2712 | |
| 2713 | final long identity = Binder.clearCallingIdentity(); |
| 2714 | try { |
| 2715 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2716 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2717 | } finally { |
| 2718 | Binder.restoreCallingIdentity(identity); |
| 2719 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2723 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2724 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2725 | |
| 2726 | final long identity = Binder.clearCallingIdentity(); |
| 2727 | try { |
| 2728 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2729 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | } finally { |
| 2731 | Binder.restoreCallingIdentity(identity); |
| 2732 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2736 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2737 | String callingPackage, int subId) { |
| 2738 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2739 | |
| 2740 | final long identity = Binder.clearCallingIdentity(); |
| 2741 | try { |
| 2742 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2743 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(identity); |
| 2746 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2750 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2751 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2752 | |
| 2753 | final long identity = Binder.clearCallingIdentity(); |
| 2754 | try { |
| 2755 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2756 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2757 | } finally { |
| 2758 | Binder.restoreCallingIdentity(identity); |
| 2759 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | @Override |
| 2763 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2764 | String number, int port, String text, PendingIntent sentIntent) { |
| 2765 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2766 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2767 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2768 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2769 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2770 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2771 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2772 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2773 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2774 | * Sets the voice activation state of a given subId. |
| 2775 | */ |
| 2776 | @Override |
| 2777 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2778 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2779 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2780 | |
| 2781 | final long identity = Binder.clearCallingIdentity(); |
| 2782 | try { |
| 2783 | final Phone phone = getPhone(subId); |
| 2784 | if (phone != null) { |
| 2785 | phone.setVoiceActivationState(activationState); |
| 2786 | } else { |
| 2787 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2788 | } |
| 2789 | } finally { |
| 2790 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2791 | } |
| 2792 | } |
| 2793 | |
| 2794 | /** |
| 2795 | * Sets the data activation state of a given subId. |
| 2796 | */ |
| 2797 | @Override |
| 2798 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2800 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | |
| 2802 | final long identity = Binder.clearCallingIdentity(); |
| 2803 | try { |
| 2804 | final Phone phone = getPhone(subId); |
| 2805 | if (phone != null) { |
| 2806 | phone.setDataActivationState(activationState); |
| 2807 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2808 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2809 | } |
| 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | /** |
| 2816 | * Returns the voice activation state of a given subId. |
| 2817 | */ |
| 2818 | @Override |
| 2819 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2820 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2821 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2822 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2823 | final long identity = Binder.clearCallingIdentity(); |
| 2824 | try { |
| 2825 | if (phone != null) { |
| 2826 | return phone.getVoiceActivationState(); |
| 2827 | } else { |
| 2828 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2829 | } |
| 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | /** |
| 2836 | * Returns the data activation state of a given subId. |
| 2837 | */ |
| 2838 | @Override |
| 2839 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2840 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2841 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2842 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2843 | final long identity = Binder.clearCallingIdentity(); |
| 2844 | try { |
| 2845 | if (phone != null) { |
| 2846 | return phone.getDataActivationState(); |
| 2847 | } else { |
| 2848 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2849 | } |
| 2850 | } finally { |
| 2851 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2856 | * Returns the unread count of voicemails for a subId |
| 2857 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2858 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2859 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2860 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2861 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2862 | return 0; |
| 2863 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2864 | final long identity = Binder.clearCallingIdentity(); |
| 2865 | try { |
| 2866 | final Phone phone = getPhone(subId); |
| 2867 | if (phone != null) { |
| 2868 | return phone.getVoiceMessageCount(); |
| 2869 | } else { |
| 2870 | return 0; |
| 2871 | } |
| 2872 | } finally { |
| 2873 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2874 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2878 | * returns true, if the device is in a state where both voice and data |
| 2879 | * are supported simultaneously. This can change based on location or network condition. |
| 2880 | */ |
| 2881 | @Override |
| 2882 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2883 | final long identity = Binder.clearCallingIdentity(); |
| 2884 | try { |
| 2885 | final Phone phone = getPhone(subId); |
| 2886 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2887 | } finally { |
| 2888 | Binder.restoreCallingIdentity(identity); |
| 2889 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2893 | * Send the dialer code if called from the current default dialer or the caller has |
| 2894 | * carrier privilege. |
| 2895 | * @param inputCode The dialer code to send |
| 2896 | */ |
| 2897 | @Override |
| 2898 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2899 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2900 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2901 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 2902 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2903 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2904 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2905 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2907 | |
| 2908 | final long identity = Binder.clearCallingIdentity(); |
| 2909 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2910 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(identity); |
| 2913 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2914 | } |
| 2915 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2916 | @Override |
| 2917 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2918 | if (!isActiveSubscription(subId)) { |
| 2919 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2920 | } |
| 2921 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2922 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2923 | } |
| 2924 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2925 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2926 | public boolean isInEmergencySmsMode() { |
| 2927 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2928 | final long identity = Binder.clearCallingIdentity(); |
| 2929 | try { |
| 2930 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2931 | if (phone.isInEmergencySmsMode()) { |
| 2932 | return true; |
| 2933 | } |
| 2934 | } |
| 2935 | } finally { |
| 2936 | Binder.restoreCallingIdentity(identity); |
| 2937 | } |
| 2938 | return false; |
| 2939 | } |
| 2940 | |
| 2941 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2942 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2943 | throws RemoteException { |
| 2944 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 2945 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2946 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2947 | "IMS not available on device."); |
| 2948 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2949 | final long token = Binder.clearCallingIdentity(); |
| 2950 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2951 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2952 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2953 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2954 | } catch (ImsException e) { |
| 2955 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(token); |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2962 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2963 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2964 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2965 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2966 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2967 | final long token = Binder.clearCallingIdentity(); |
| 2968 | try { |
| 2969 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2970 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 2971 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2972 | } catch (ImsException e) { |
| 2973 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2974 | + "is inactive, ignoring unregister."); |
| 2975 | // If the subscription is no longer active, just return, since the callback |
| 2976 | // will already have been removed internally. |
| 2977 | } finally { |
| 2978 | Binder.restoreCallingIdentity(token); |
| 2979 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 2982 | /** |
| 2983 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 2984 | */ |
| 2985 | @Override |
| 2986 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 2987 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 2988 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2989 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2990 | "IMS not available on device."); |
| 2991 | } |
| 2992 | final long token = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | Phone phone = getPhone(subId); |
| 2995 | if (phone == null) { |
| 2996 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 2997 | + subId + "'"); |
| 2998 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 2999 | } |
| 3000 | phone.getImsRegistrationState(regState -> { |
| 3001 | try { |
| 3002 | consumer.accept((regState == null) |
| 3003 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3004 | } catch (RemoteException e) { |
| 3005 | // Ignore if the remote process is no longer available to call back. |
| 3006 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3007 | } |
| 3008 | }); |
| 3009 | } finally { |
| 3010 | Binder.restoreCallingIdentity(token); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | /** |
| 3015 | * Get the transport type for the IMS service registration state. |
| 3016 | */ |
| 3017 | @Override |
| 3018 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
| 3019 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3020 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3021 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3022 | "IMS not available on device."); |
| 3023 | } |
| 3024 | final long token = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | Phone phone = getPhone(subId); |
| 3027 | if (phone == null) { |
| 3028 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3029 | + subId + "'"); |
| 3030 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3031 | } |
| 3032 | phone.getImsRegistrationTech(regTech -> { |
| 3033 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3034 | int regTechConverted = (regTech == null) |
| 3035 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3036 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3037 | regTechConverted); |
| 3038 | try { |
| 3039 | consumer.accept(regTechConverted); |
| 3040 | } catch (RemoteException e) { |
| 3041 | // Ignore if the remote process is no longer available to call back. |
| 3042 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3043 | } |
| 3044 | }); |
| 3045 | } finally { |
| 3046 | Binder.restoreCallingIdentity(token); |
| 3047 | } |
| 3048 | } |
| 3049 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3050 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3051 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3052 | throws RemoteException { |
| 3053 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3054 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3055 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3056 | "IMS not available on device."); |
| 3057 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3058 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3059 | final long token = Binder.clearCallingIdentity(); |
| 3060 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3061 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3062 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3063 | } catch (ImsException e) { |
| 3064 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3065 | } finally { |
| 3066 | Binder.restoreCallingIdentity(token); |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3071 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 3072 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3073 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3074 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3075 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3076 | |
| 3077 | final long token = Binder.clearCallingIdentity(); |
| 3078 | try { |
| 3079 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3080 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3081 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3082 | } catch (ImsException e) { |
| 3083 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3084 | + "is inactive, ignoring unregister."); |
| 3085 | // If the subscription is no longer active, just return, since the callback |
| 3086 | // will already have been removed internally. |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(token); |
| 3089 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3093 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3094 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3095 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3096 | final long token = Binder.clearCallingIdentity(); |
| 3097 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3098 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3099 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3100 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3101 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3102 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3103 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3104 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3105 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3106 | } finally { |
| 3107 | Binder.restoreCallingIdentity(token); |
| 3108 | } |
| 3109 | } |
| 3110 | |
| 3111 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3112 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3113 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3114 | final long token = Binder.clearCallingIdentity(); |
| 3115 | try { |
| 3116 | Phone phone = getPhone(subId); |
| 3117 | if (phone == null) return false; |
| 3118 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3119 | } finally { |
| 3120 | Binder.restoreCallingIdentity(token); |
| 3121 | } |
| 3122 | } |
| 3123 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3124 | /** |
| 3125 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3126 | * subscription. |
| 3127 | * @param subId The subscription to use to check the configuration. |
| 3128 | * @param callback The callback that will be used to send the result. |
| 3129 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3130 | * @param transportType The transport type of the MmTelFeature capability. |
| 3131 | */ |
| 3132 | @Override |
| 3133 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3134 | int transportType) { |
| 3135 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3136 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3137 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3138 | "IMS not available on device."); |
| 3139 | } |
| 3140 | final long token = Binder.clearCallingIdentity(); |
| 3141 | try { |
| 3142 | int slotId = getSlotIndex(subId); |
| 3143 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3144 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3145 | + subId + "'"); |
| 3146 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3147 | } |
| 3148 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3149 | transportType, aBoolean -> { |
| 3150 | try { |
| 3151 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3152 | } catch (RemoteException e) { |
| 3153 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3154 | + "running. Ignore"); |
| 3155 | } |
| 3156 | }); |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(token); |
| 3159 | } |
| 3160 | } |
| 3161 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3162 | @Override |
| 3163 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 3164 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 3165 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3166 | final long token = Binder.clearCallingIdentity(); |
| 3167 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3168 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3169 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3170 | } catch (ImsException e) { |
| 3171 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3172 | } finally { |
| 3173 | Binder.restoreCallingIdentity(token); |
| 3174 | } |
| 3175 | } |
| 3176 | |
| 3177 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3178 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3179 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3180 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3181 | final long identity = Binder.clearCallingIdentity(); |
| 3182 | try { |
| 3183 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3184 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3185 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3186 | } catch (ImsException e) { |
| 3187 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3188 | } finally { |
| 3189 | Binder.restoreCallingIdentity(identity); |
| 3190 | } |
| 3191 | } |
| 3192 | |
| 3193 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3194 | public boolean isVtSettingEnabled(int subId) { |
| 3195 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3196 | final long identity = Binder.clearCallingIdentity(); |
| 3197 | try { |
| 3198 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3199 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3200 | } catch (ImsException e) { |
| 3201 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3202 | } finally { |
| 3203 | Binder.restoreCallingIdentity(identity); |
| 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3208 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3209 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3210 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3211 | final long identity = Binder.clearCallingIdentity(); |
| 3212 | try { |
| 3213 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3214 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3215 | } catch (ImsException e) { |
| 3216 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3217 | } finally { |
| 3218 | Binder.restoreCallingIdentity(identity); |
| 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | @Override |
| 3223 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3224 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3225 | final long identity = Binder.clearCallingIdentity(); |
| 3226 | try { |
| 3227 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3228 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3229 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3230 | } catch (ImsException e) { |
| 3231 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3232 | } finally { |
| 3233 | Binder.restoreCallingIdentity(identity); |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3238 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3240 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3241 | final long identity = Binder.clearCallingIdentity(); |
| 3242 | try { |
| 3243 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3244 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3245 | } catch (ImsException e) { |
| 3246 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3247 | } finally { |
| 3248 | Binder.restoreCallingIdentity(identity); |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | @Override |
| 3253 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3254 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3255 | final long identity = Binder.clearCallingIdentity(); |
| 3256 | try { |
| 3257 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3258 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3259 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3260 | } catch (ImsException e) { |
| 3261 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3262 | } finally { |
| 3263 | Binder.restoreCallingIdentity(identity); |
| 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3268 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3269 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3270 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3271 | final long identity = Binder.clearCallingIdentity(); |
| 3272 | try { |
| 3273 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3274 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3275 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3276 | } catch (ImsException e) { |
| 3277 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3278 | } finally { |
| 3279 | Binder.restoreCallingIdentity(identity); |
| 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | @Override |
| 3284 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3285 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3286 | "setVoWiFiNonPersistent"); |
| 3287 | final long identity = Binder.clearCallingIdentity(); |
| 3288 | try { |
| 3289 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3290 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3291 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3292 | } catch (ImsException e) { |
| 3293 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3294 | } finally { |
| 3295 | Binder.restoreCallingIdentity(identity); |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | @Override |
| 3300 | public int getVoWiFiModeSetting(int subId) { |
| 3301 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3302 | final long identity = Binder.clearCallingIdentity(); |
| 3303 | try { |
| 3304 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3305 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3306 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3307 | } catch (ImsException e) { |
| 3308 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3309 | } finally { |
| 3310 | Binder.restoreCallingIdentity(identity); |
| 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | @Override |
| 3315 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3317 | "setVoWiFiModeSetting"); |
| 3318 | final long identity = Binder.clearCallingIdentity(); |
| 3319 | try { |
| 3320 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3321 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3322 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3323 | } catch (ImsException e) { |
| 3324 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3325 | } finally { |
| 3326 | Binder.restoreCallingIdentity(identity); |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | @Override |
| 3331 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3332 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3333 | final long identity = Binder.clearCallingIdentity(); |
| 3334 | try { |
| 3335 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3336 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3337 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3338 | } catch (ImsException e) { |
| 3339 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(identity); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | @Override |
| 3346 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3347 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3348 | "setVoWiFiRoamingModeSetting"); |
| 3349 | final long identity = Binder.clearCallingIdentity(); |
| 3350 | try { |
| 3351 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3352 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3353 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3354 | } catch (ImsException e) { |
| 3355 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3356 | } finally { |
| 3357 | Binder.restoreCallingIdentity(identity); |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | @Override |
| 3362 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3363 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3364 | "setRttCapabilityEnabled"); |
| 3365 | final long identity = Binder.clearCallingIdentity(); |
| 3366 | try { |
| 3367 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3368 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3369 | } catch (ImsException e) { |
| 3370 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3371 | } finally { |
| 3372 | Binder.restoreCallingIdentity(identity); |
| 3373 | } |
| 3374 | } |
| 3375 | |
| 3376 | @Override |
| 3377 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3378 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3379 | final long identity = Binder.clearCallingIdentity(); |
| 3380 | try { |
| 3381 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3382 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3383 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3384 | } catch (ImsException e) { |
| 3385 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3386 | } finally { |
| 3387 | Binder.restoreCallingIdentity(identity); |
| 3388 | } |
| 3389 | } |
| 3390 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3391 | @Override |
| 3392 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3393 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3394 | final long identity = Binder.clearCallingIdentity(); |
| 3395 | try { |
| 3396 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3397 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3398 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3399 | } catch (ImsException e) { |
| 3400 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3401 | } finally { |
| 3402 | Binder.restoreCallingIdentity(identity); |
| 3403 | } |
| 3404 | } |
| 3405 | |
| 3406 | @Override |
| 3407 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3408 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3409 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3410 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3411 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3412 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3413 | try { |
| 3414 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3415 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3416 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3417 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3418 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3419 | + "is inactive, ignoring unregister."); |
| 3420 | // If the subscription is no longer active, just return, since the callback will already |
| 3421 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3422 | } finally { |
| 3423 | Binder.restoreCallingIdentity(identity); |
| 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3428 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3429 | boolean isProvisioned) { |
| 3430 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3431 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3432 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3433 | } |
| 3434 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3435 | "setProvisioningStatusForCapability"); |
| 3436 | final long identity = Binder.clearCallingIdentity(); |
| 3437 | try { |
| 3438 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3439 | Phone phone = getPhone(subId); |
| 3440 | if (phone == null) { |
| 3441 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3442 | + subId); |
| 3443 | return; |
| 3444 | } |
| 3445 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3446 | return; |
| 3447 | } |
| 3448 | |
| 3449 | // this capability requires provisioning, route to the correct API. |
| 3450 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3451 | switch (capability) { |
| 3452 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3453 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3454 | ims.setVolteProvisioned(isProvisioned); |
| 3455 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3456 | ims.setWfcProvisioned(isProvisioned); |
| 3457 | } |
| 3458 | break; |
| 3459 | } |
| 3460 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3461 | // There is currently no difference in VT provisioning type. |
| 3462 | ims.setVtProvisioned(isProvisioned); |
| 3463 | break; |
| 3464 | } |
| 3465 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3466 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3467 | // change the capability of the feature instead if needed. |
| 3468 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3469 | == isProvisioned) { |
| 3470 | // No change in provisioning. |
| 3471 | return; |
| 3472 | } |
| 3473 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3474 | try { |
| 3475 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3476 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3477 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3478 | + ", Exception" + e.getMessage()); |
| 3479 | } |
| 3480 | break; |
| 3481 | } |
| 3482 | default: { |
| 3483 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3484 | + capability + "', which does not require provisioning."); |
| 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | } finally { |
| 3489 | Binder.restoreCallingIdentity(identity); |
| 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | @Override |
| 3494 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3495 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3496 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3497 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3498 | } |
| 3499 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3500 | final long identity = Binder.clearCallingIdentity(); |
| 3501 | try { |
| 3502 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3503 | Phone phone = getPhone(subId); |
| 3504 | if (phone == null) { |
| 3505 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3506 | + subId); |
| 3507 | // We will fail with "true" as the provisioning status because this is the default |
| 3508 | // if we do not require provisioning. |
| 3509 | return true; |
| 3510 | } |
| 3511 | |
| 3512 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3513 | return true; |
| 3514 | } |
| 3515 | |
| 3516 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3517 | switch (capability) { |
| 3518 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3519 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3520 | return ims.isVolteProvisionedOnDevice(); |
| 3521 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3522 | return ims.isWfcProvisionedOnDevice(); |
| 3523 | } |
| 3524 | // This should never happen, since we are checking tech above to make sure it |
| 3525 | // is either LTE or IWLAN. |
| 3526 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3527 | + "capability."); |
| 3528 | } |
| 3529 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3530 | // There is currently no difference in VT provisioning type. |
| 3531 | return ims.isVtProvisionedOnDevice(); |
| 3532 | } |
| 3533 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3534 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3535 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3536 | } |
| 3537 | default: { |
| 3538 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3539 | + capability + "', which does not require provisioning."); |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | } finally { |
| 3544 | Binder.restoreCallingIdentity(identity); |
| 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | @Override |
| 3549 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3550 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3551 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3552 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3553 | } |
| 3554 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3555 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3556 | return (provisionedBits & capability) > 0; |
| 3557 | } |
| 3558 | |
| 3559 | @Override |
| 3560 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3561 | boolean isProvisioned) { |
| 3562 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3563 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3564 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3565 | } |
| 3566 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3567 | "setProvisioningStatusForCapability"); |
| 3568 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3569 | // If the current provisioning status for capability already matches isProvisioned, |
| 3570 | // do nothing. |
| 3571 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3572 | return; |
| 3573 | } |
| 3574 | if (isProvisioned) { |
| 3575 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3576 | } else { |
| 3577 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | /** |
| 3582 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3583 | * technology. The bitfield should mirror the bitfield defined by |
| 3584 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3585 | */ |
| 3586 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3587 | String key = getMmTelProvisioningKey(subId, tech); |
| 3588 | // Default is no capabilities are provisioned. |
| 3589 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3590 | } |
| 3591 | |
| 3592 | /** |
| 3593 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3594 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3595 | * technology specified. |
| 3596 | * |
| 3597 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3598 | */ |
| 3599 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3600 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3601 | String key = getMmTelProvisioningKey(subId, tech); |
| 3602 | editor.putInt(key, newField); |
| 3603 | editor.commit(); |
| 3604 | } |
| 3605 | |
| 3606 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3607 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3608 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3609 | } |
| 3610 | |
| 3611 | /** |
| 3612 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3613 | * carrier associated with the subscription id. |
| 3614 | */ |
| 3615 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3616 | int capability) { |
| 3617 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3618 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3619 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3620 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3621 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3622 | false); |
| 3623 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3624 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3625 | |
| 3626 | // First check to make sure that the capability requires provisioning. |
| 3627 | switch (capability) { |
| 3628 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3629 | // intentional fallthrough |
| 3630 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3631 | if (requireVoiceVtProvisioning) { |
| 3632 | // Voice and Video requires provisioning |
| 3633 | return true; |
| 3634 | } |
| 3635 | break; |
| 3636 | } |
| 3637 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3638 | if (requireUtProvisioning) { |
| 3639 | // UT requires provisioning |
| 3640 | return true; |
| 3641 | } |
| 3642 | break; |
| 3643 | } |
| 3644 | } |
| 3645 | return false; |
| 3646 | } |
| 3647 | |
| 3648 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3649 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3650 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3651 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3652 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3653 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3654 | final long identity = Binder.clearCallingIdentity(); |
| 3655 | try { |
| 3656 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3657 | int slotId = getSlotIndex(subId); |
| 3658 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3659 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3660 | + subId + "' for key:" + key); |
| 3661 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3662 | } |
| 3663 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3664 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3665 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3666 | + subId + "' for key:" + key); |
| 3667 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(identity); |
| 3670 | } |
| 3671 | } |
| 3672 | |
| 3673 | @Override |
| 3674 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3675 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3676 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3677 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3678 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3679 | final long identity = Binder.clearCallingIdentity(); |
| 3680 | try { |
| 3681 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3682 | int slotId = getSlotIndex(subId); |
| 3683 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3684 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3685 | + subId + "' for key:" + key); |
| 3686 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3687 | } |
| 3688 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3689 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3690 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3691 | + subId + "' for key:" + key); |
| 3692 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3693 | } finally { |
| 3694 | Binder.restoreCallingIdentity(identity); |
| 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | @Override |
| 3699 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3700 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3701 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3702 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3703 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3704 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3705 | final long identity = Binder.clearCallingIdentity(); |
| 3706 | try { |
| 3707 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3708 | int slotId = getSlotIndex(subId); |
| 3709 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3710 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3711 | + subId + "' for key:" + key); |
| 3712 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3713 | } |
| 3714 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3715 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3716 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3717 | + "' for key:" + key); |
| 3718 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3719 | } finally { |
| 3720 | Binder.restoreCallingIdentity(identity); |
| 3721 | } |
| 3722 | } |
| 3723 | |
| 3724 | @Override |
| 3725 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3726 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3727 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3728 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3729 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3730 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3731 | final long identity = Binder.clearCallingIdentity(); |
| 3732 | try { |
| 3733 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3734 | int slotId = getSlotIndex(subId); |
| 3735 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3736 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3737 | + subId + "' for key:" + key); |
| 3738 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3739 | } |
| 3740 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3741 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3742 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3743 | + "' for key:" + key); |
| 3744 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3745 | } finally { |
| 3746 | Binder.restoreCallingIdentity(identity); |
| 3747 | } |
| 3748 | } |
| 3749 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3750 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3751 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3752 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3753 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3754 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3755 | } |
| 3756 | return slotId; |
| 3757 | } |
| 3758 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3759 | private int getSlotIndex(int subId) { |
| 3760 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3761 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3762 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3763 | } |
| 3764 | return slotId; |
| 3765 | } |
| 3766 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3767 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3768 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3769 | */ |
| 3770 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3771 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3772 | final int targetSdk = getTargetSdk(callingPackage); |
| 3773 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| 3774 | return getDataNetworkTypeForSubscriber(subId, callingPackage); |
| 3775 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3776 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3777 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3778 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3779 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3780 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3781 | final long identity = Binder.clearCallingIdentity(); |
| 3782 | try { |
| 3783 | final Phone phone = getPhone(subId); |
| 3784 | if (phone != null) { |
| 3785 | return phone.getServiceState().getDataNetworkType(); |
| 3786 | } else { |
| 3787 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3788 | } |
| 3789 | } finally { |
| 3790 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3791 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | /** |
| 3795 | * Returns the data network type |
| 3796 | */ |
| 3797 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3798 | public int getDataNetworkType(String callingPackage) { |
| 3799 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | /** |
| 3803 | * Returns the data network type for a subId |
| 3804 | */ |
| 3805 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3806 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3807 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3808 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3809 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3810 | } |
| 3811 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3812 | final long identity = Binder.clearCallingIdentity(); |
| 3813 | try { |
| 3814 | final Phone phone = getPhone(subId); |
| 3815 | if (phone != null) { |
| 3816 | return phone.getServiceState().getDataNetworkType(); |
| 3817 | } else { |
| 3818 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3819 | } |
| 3820 | } finally { |
| 3821 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3822 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3826 | * Returns the Voice network type for a subId |
| 3827 | */ |
| 3828 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3829 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3830 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3831 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3832 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3833 | } |
| 3834 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3835 | final long identity = Binder.clearCallingIdentity(); |
| 3836 | try { |
| 3837 | final Phone phone = getPhone(subId); |
| 3838 | if (phone != null) { |
| 3839 | return phone.getServiceState().getVoiceNetworkType(); |
| 3840 | } else { |
| 3841 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3842 | } |
| 3843 | } finally { |
| 3844 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3845 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | /** |
| 3849 | * @return true if a ICC card is present |
| 3850 | */ |
| 3851 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3852 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3853 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3854 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3858 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3859 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3860 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3861 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3862 | final long identity = Binder.clearCallingIdentity(); |
| 3863 | try { |
| 3864 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3865 | if (phone != null) { |
| 3866 | return phone.getIccCard().hasIccCard(); |
| 3867 | } else { |
| 3868 | return false; |
| 3869 | } |
| 3870 | } finally { |
| 3871 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3872 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | /** |
| 3876 | * Return if the current radio is LTE on CDMA. This |
| 3877 | * is a tri-state return value as for a period of time |
| 3878 | * the mode may be unknown. |
| 3879 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3880 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3881 | * @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] | 3882 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3883 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3884 | @Override |
| 3885 | public int getLteOnCdmaMode(String callingPackage) { |
| 3886 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3887 | } |
| 3888 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3889 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3890 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3891 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3892 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3893 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3894 | } |
| 3895 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3896 | final long identity = Binder.clearCallingIdentity(); |
| 3897 | try { |
| 3898 | final Phone phone = getPhone(subId); |
| 3899 | if (phone == null) { |
| 3900 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3901 | } else { |
| 3902 | return phone.getLteOnCdmaMode(); |
| 3903 | } |
| 3904 | } finally { |
| 3905 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3906 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3909 | /** |
| 3910 | * {@hide} |
| 3911 | * Returns Default subId, 0 in the case of single standby. |
| 3912 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3913 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3914 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3917 | private int getSlotForDefaultSubscription() { |
| 3918 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3919 | } |
| 3920 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3921 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3922 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3923 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3924 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3925 | private boolean isActiveSubscription(int subId) { |
| 3926 | return mSubscriptionController.isActiveSubId(subId); |
| 3927 | } |
| 3928 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3929 | /** |
| 3930 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3931 | */ |
| 3932 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3935 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3936 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3937 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3938 | } finally { |
| 3939 | Binder.restoreCallingIdentity(identity); |
| 3940 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | /** |
| 3944 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3945 | */ |
| 3946 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3947 | final long identity = Binder.clearCallingIdentity(); |
| 3948 | try { |
| 3949 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3950 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3951 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3952 | } finally { |
| 3953 | Binder.restoreCallingIdentity(identity); |
| 3954 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3955 | } |
| 3956 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3957 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3958 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3959 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3960 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3961 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3962 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3963 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3964 | if (phoneId == -1) { |
| 3965 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3966 | + " does not correspond to an active phone"); |
| 3967 | } |
| 3968 | return PhoneFactory.getPhone(phoneId); |
| 3969 | } |
| 3970 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3971 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3972 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3973 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3975 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3976 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3977 | if (DBG) { |
| 3978 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3979 | } |
| 3980 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3981 | p2); |
| 3982 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3983 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3984 | |
| 3985 | @Override |
| 3986 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3987 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3988 | enforceModifyPermission(); |
| 3989 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3990 | if (DBG) { |
| 3991 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3992 | } |
| 3993 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3994 | callingPackage, aid, p2); |
| 3995 | } |
| 3996 | |
| 3997 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3998 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3999 | final long identity = Binder.clearCallingIdentity(); |
| 4000 | try { |
| 4001 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4002 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4003 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4004 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4005 | if (bestComponent == null |
| 4006 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4007 | loge("The calling package is not allowed to access ISD-R."); |
| 4008 | throw new SecurityException( |
| 4009 | "The calling package is not allowed to access ISD-R."); |
| 4010 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4011 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4012 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4013 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4014 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4015 | null /* workSource */); |
| 4016 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | return response; |
| 4018 | } finally { |
| 4019 | Binder.restoreCallingIdentity(identity); |
| 4020 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4024 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4026 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4027 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4028 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4029 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4030 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4031 | @Override |
| 4032 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4033 | enforceModifyPermission(); |
| 4034 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4035 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4036 | channel); |
| 4037 | } |
| 4038 | |
| 4039 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4040 | final long identity = Binder.clearCallingIdentity(); |
| 4041 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | if (channel < 0) { |
| 4043 | return false; |
| 4044 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4045 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4046 | null /* workSource */); |
| 4047 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4048 | return success; |
| 4049 | } finally { |
| 4050 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4051 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4055 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4056 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4057 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4058 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4059 | if (DBG) { |
| 4060 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4061 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4062 | + p3 + " data=" + data); |
| 4063 | } |
| 4064 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4065 | command, p1, p2, p3, data); |
| 4066 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4067 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4068 | @Override |
| 4069 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4070 | int command, int p1, int p2, int p3, String data) { |
| 4071 | enforceModifyPermission(); |
| 4072 | if (DBG) { |
| 4073 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4074 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4075 | + p3 + " data=" + data); |
| 4076 | } |
| 4077 | return iccTransmitApduLogicalChannelWithPermission( |
| 4078 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4079 | data); |
| 4080 | } |
| 4081 | |
| 4082 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4083 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4084 | final long identity = Binder.clearCallingIdentity(); |
| 4085 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4086 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4087 | return ""; |
| 4088 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4089 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4090 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4091 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4092 | null /* workSource */); |
| 4093 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4094 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4095 | // Append the returned status code to the end of the response payload. |
| 4096 | String s = Integer.toHexString( |
| 4097 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4098 | if (response.payload != null) { |
| 4099 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4100 | } |
| 4101 | return s; |
| 4102 | } finally { |
| 4103 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4104 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4105 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4106 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4107 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4108 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4109 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4111 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4113 | if (DBG) { |
| 4114 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4115 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4116 | } |
| 4117 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4118 | cla, command, p1, p2, p3, data); |
| 4119 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4120 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4121 | @Override |
| 4122 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4123 | int command, int p1, int p2, int p3, String data) { |
| 4124 | enforceModifyPermission(); |
| 4125 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4126 | if (DBG) { |
| 4127 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4128 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4129 | + " data=" + data); |
| 4130 | } |
| 4131 | |
| 4132 | return iccTransmitApduBasicChannelWithPermission( |
| 4133 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4134 | p2, p3, data); |
| 4135 | } |
| 4136 | |
| 4137 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4138 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4139 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4140 | final long identity = Binder.clearCallingIdentity(); |
| 4141 | try { |
| 4142 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4143 | && TextUtils.equals(ISDR_AID, data)) { |
| 4144 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4145 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4146 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4147 | if (bestComponent == null |
| 4148 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4149 | loge("The calling package is not allowed to select ISD-R."); |
| 4150 | throw new SecurityException( |
| 4151 | "The calling package is not allowed to select ISD-R."); |
| 4152 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4153 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4154 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4155 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4156 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4157 | null /* workSource */); |
| 4158 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4159 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4160 | // Append the returned status code to the end of the response payload. |
| 4161 | String s = Integer.toHexString( |
| 4162 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4163 | if (response.payload != null) { |
| 4164 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4165 | } |
| 4166 | return s; |
| 4167 | } finally { |
| 4168 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4169 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
| 4172 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4173 | 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] | 4174 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4175 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4176 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4177 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4178 | final long identity = Binder.clearCallingIdentity(); |
| 4179 | try { |
| 4180 | if (DBG) { |
| 4181 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4182 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4183 | } |
| 4184 | |
| 4185 | IccIoResult response = |
| 4186 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4187 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4188 | subId); |
| 4189 | |
| 4190 | if (DBG) { |
| 4191 | log("Exchange SIM_IO [R]" + response); |
| 4192 | } |
| 4193 | |
| 4194 | byte[] result = null; |
| 4195 | int length = 2; |
| 4196 | if (response.payload != null) { |
| 4197 | length = 2 + response.payload.length; |
| 4198 | result = new byte[length]; |
| 4199 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4200 | } else { |
| 4201 | result = new byte[length]; |
| 4202 | } |
| 4203 | |
| 4204 | result[length - 1] = (byte) response.sw2; |
| 4205 | result[length - 2] = (byte) response.sw1; |
| 4206 | return result; |
| 4207 | } finally { |
| 4208 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4209 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4210 | } |
| 4211 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4212 | /** |
| 4213 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4214 | * on a particular subscription |
| 4215 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4216 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4218 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4219 | return null; |
| 4220 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4221 | |
| 4222 | final long identity = Binder.clearCallingIdentity(); |
| 4223 | try { |
| 4224 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4225 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4226 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4227 | return null; |
| 4228 | } |
| 4229 | Object response = sendRequest( |
| 4230 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4231 | if (response instanceof String[]) { |
| 4232 | return (String[]) response; |
| 4233 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4234 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4235 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4236 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4237 | } finally { |
| 4238 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4239 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4240 | } |
| 4241 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4242 | /** |
| 4243 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4244 | * subscription. |
| 4245 | * |
| 4246 | * @param subId the id of the subscription. |
| 4247 | * @param appType the uicc app type, must be USIM or SIM. |
| 4248 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4249 | * @param callingPackage the op Package name. |
| 4250 | * @return number of fplmns that is successfully written to the SIM. |
| 4251 | */ |
| 4252 | public int setForbiddenPlmns( |
| 4253 | int subId, int appType, List<String> fplmns, String callingPackage) { |
| 4254 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4255 | mApp, subId, callingPackage, "setForbiddenPlmns")) { |
| 4256 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4257 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4258 | } |
| 4259 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4260 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4261 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4262 | } |
| 4263 | if (fplmns == null) { |
| 4264 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4265 | } |
| 4266 | for (String fplmn : fplmns) { |
| 4267 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4268 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4269 | } |
| 4270 | } |
| 4271 | final long identity = Binder.clearCallingIdentity(); |
| 4272 | try { |
| 4273 | Object response = sendRequest( |
| 4274 | CMD_SET_FORBIDDEN_PLMNS, |
| 4275 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4276 | subId); |
| 4277 | return (int) response; |
| 4278 | } finally { |
| 4279 | Binder.restoreCallingIdentity(identity); |
| 4280 | } |
| 4281 | } |
| 4282 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4283 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4284 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4285 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4286 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4287 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4288 | final long identity = Binder.clearCallingIdentity(); |
| 4289 | try { |
| 4290 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4291 | if (response.payload == null) { |
| 4292 | return ""; |
| 4293 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4294 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4295 | // Append the returned status code to the end of the response payload. |
| 4296 | String s = Integer.toHexString( |
| 4297 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4298 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4299 | return s; |
| 4300 | } finally { |
| 4301 | Binder.restoreCallingIdentity(identity); |
| 4302 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4303 | } |
| 4304 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4305 | /** |
| 4306 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4307 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4308 | * |
| 4309 | * @param itemID the ID of the item to read |
| 4310 | * @return the NV item as a String, or null on error. |
| 4311 | */ |
| 4312 | @Override |
| 4313 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4314 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4315 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4316 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4317 | |
| 4318 | final long identity = Binder.clearCallingIdentity(); |
| 4319 | try { |
| 4320 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4321 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4322 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4323 | return value; |
| 4324 | } finally { |
| 4325 | Binder.restoreCallingIdentity(identity); |
| 4326 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | /** |
| 4330 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4331 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4332 | * |
| 4333 | * @param itemID the ID of the item to read |
| 4334 | * @param itemValue the value to write, as a String |
| 4335 | * @return true on success; false on any failure |
| 4336 | */ |
| 4337 | @Override |
| 4338 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4339 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4341 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4342 | |
| 4343 | final long identity = Binder.clearCallingIdentity(); |
| 4344 | try { |
| 4345 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4346 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4347 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4348 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4349 | return success; |
| 4350 | } finally { |
| 4351 | Binder.restoreCallingIdentity(identity); |
| 4352 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | /** |
| 4356 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4357 | * Used for device configuration by some CDMA operators. |
| 4358 | * |
| 4359 | * @param preferredRoamingList byte array containing the new PRL |
| 4360 | * @return true on success; false on any failure |
| 4361 | */ |
| 4362 | @Override |
| 4363 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4364 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4365 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4366 | |
| 4367 | final long identity = Binder.clearCallingIdentity(); |
| 4368 | try { |
| 4369 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4370 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4371 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4372 | return success; |
| 4373 | } finally { |
| 4374 | Binder.restoreCallingIdentity(identity); |
| 4375 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4376 | } |
| 4377 | |
| 4378 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4379 | * 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] | 4380 | * Used for device configuration by some CDMA operators. |
| 4381 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4382 | * @param slotIndex - device slot. |
| 4383 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4384 | * @return true on success; false on any failure |
| 4385 | */ |
| 4386 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4387 | public boolean resetModemConfig(int slotIndex) { |
| 4388 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4389 | if (phone != null) { |
| 4390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4391 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4393 | final long identity = Binder.clearCallingIdentity(); |
| 4394 | try { |
| 4395 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4396 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4397 | return success; |
| 4398 | } finally { |
| 4399 | Binder.restoreCallingIdentity(identity); |
| 4400 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4401 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4402 | return false; |
| 4403 | } |
| 4404 | |
| 4405 | /** |
| 4406 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4407 | * |
| 4408 | * @param slotIndex - device slot. |
| 4409 | * |
| 4410 | * @return true on success; false on any failure |
| 4411 | */ |
| 4412 | @Override |
| 4413 | public boolean rebootModem(int slotIndex) { |
| 4414 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4415 | if (phone != null) { |
| 4416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4417 | mApp, phone.getSubId(), "rebootModem"); |
| 4418 | |
| 4419 | final long identity = Binder.clearCallingIdentity(); |
| 4420 | try { |
| 4421 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4422 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4423 | return success; |
| 4424 | } finally { |
| 4425 | Binder.restoreCallingIdentity(identity); |
| 4426 | } |
| 4427 | } |
| 4428 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4429 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4430 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4431 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4432 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4433 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4434 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4435 | return new String[0]; |
| 4436 | } |
| 4437 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4438 | final long identity = Binder.clearCallingIdentity(); |
| 4439 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4440 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4441 | } finally { |
| 4442 | Binder.restoreCallingIdentity(identity); |
| 4443 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4446 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4447 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4448 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4449 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4450 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4451 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4452 | |
| 4453 | final long identity = Binder.clearCallingIdentity(); |
| 4454 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4455 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4456 | if (resolver == null) { |
| 4457 | // may happen if the device does not support IMS. |
| 4458 | return; |
| 4459 | } |
| 4460 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4461 | } finally { |
| 4462 | Binder.restoreCallingIdentity(identity); |
| 4463 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4467 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4468 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4469 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4470 | public void disableIms(int slotId) { |
| 4471 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | |
| 4473 | final long identity = Binder.clearCallingIdentity(); |
| 4474 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4475 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4476 | if (resolver == null) { |
| 4477 | // may happen if the device does not support IMS. |
| 4478 | return; |
| 4479 | } |
| 4480 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4481 | } finally { |
| 4482 | Binder.restoreCallingIdentity(identity); |
| 4483 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | /** |
| 4487 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4488 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4489 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4490 | */ |
| 4491 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4492 | IImsServiceFeatureCallback callback) { |
| 4493 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4494 | |
| 4495 | final long identity = Binder.clearCallingIdentity(); |
| 4496 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4497 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4498 | if (resolver == null) { |
| 4499 | // may happen if the device does not support IMS. |
| 4500 | return null; |
| 4501 | } |
| 4502 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4503 | } finally { |
| 4504 | Binder.restoreCallingIdentity(identity); |
| 4505 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | /** |
| 4509 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4510 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4511 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4512 | * listener for feature updates. |
| 4513 | */ |
| 4514 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4515 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4516 | |
| 4517 | final long identity = Binder.clearCallingIdentity(); |
| 4518 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4519 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4520 | if (resolver == null) { |
| 4521 | // may happen if the device does not support IMS. |
| 4522 | return null; |
| 4523 | } |
| 4524 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | } finally { |
| 4526 | Binder.restoreCallingIdentity(identity); |
| 4527 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4528 | } |
| 4529 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4530 | /** |
| 4531 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4532 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4533 | */ |
| 4534 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4535 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4536 | |
| 4537 | final long identity = Binder.clearCallingIdentity(); |
| 4538 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4539 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4540 | if (resolver == null) { |
| 4541 | // may happen if the device does not support IMS. |
| 4542 | return null; |
| 4543 | } |
| 4544 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4545 | } finally { |
| 4546 | Binder.restoreCallingIdentity(identity); |
| 4547 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4548 | } |
| 4549 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4550 | /** |
| 4551 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4552 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4553 | */ |
| 4554 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4555 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4556 | |
| 4557 | final long identity = Binder.clearCallingIdentity(); |
| 4558 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4559 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4560 | if (resolver == null) { |
| 4561 | // may happen if the device does not support IMS. |
| 4562 | return null; |
| 4563 | } |
| 4564 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4565 | } finally { |
| 4566 | Binder.restoreCallingIdentity(identity); |
| 4567 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4568 | } |
| 4569 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4570 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4571 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4572 | * |
| 4573 | * @param slotId the slot ID that the ImsService should bind for. |
| 4574 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4575 | * ImsService is the device default ImsService. |
| 4576 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4577 | * to. |
| 4578 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4579 | * @hide |
| 4580 | */ |
| 4581 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4582 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4583 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4584 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4585 | "setImsService"); |
| 4586 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4587 | final long identity = Binder.clearCallingIdentity(); |
| 4588 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4589 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4590 | if (resolver == null) { |
| 4591 | // may happen if the device does not support IMS. |
| 4592 | return false; |
| 4593 | } |
| 4594 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4595 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4596 | } finally { |
| 4597 | Binder.restoreCallingIdentity(identity); |
| 4598 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | /** |
| 4602 | * Return the ImsService configuration. |
| 4603 | * |
| 4604 | * @param slotId The slot that the ImsService is associated with. |
| 4605 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4606 | * the device default. |
| 4607 | * @return the package name of the ImsService configuration. |
| 4608 | */ |
| 4609 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4610 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4611 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4612 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4613 | "getImsService"); |
| 4614 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4615 | final long identity = Binder.clearCallingIdentity(); |
| 4616 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4617 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4618 | if (resolver == null) { |
| 4619 | // may happen if the device does not support IMS. |
| 4620 | return ""; |
| 4621 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame^] | 4622 | // TODO: change API to query RCS separately. |
| 4623 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 4624 | ImsFeature.FEATURE_MMTEL); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4625 | } finally { |
| 4626 | Binder.restoreCallingIdentity(identity); |
| 4627 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4630 | /** |
| 4631 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4632 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4633 | * @param callback A callback with an integer containing the |
| 4634 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4635 | */ |
| 4636 | @Override |
| 4637 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4638 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4639 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4640 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4641 | "IMS not available on device."); |
| 4642 | } |
| 4643 | final long token = Binder.clearCallingIdentity(); |
| 4644 | try { |
| 4645 | int slotId = getSlotIndex(subId); |
| 4646 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4647 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4648 | + subId + "'"); |
| 4649 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4650 | } |
| 4651 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4652 | try { |
| 4653 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4654 | } catch (RemoteException e) { |
| 4655 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4656 | + "Ignore"); |
| 4657 | } |
| 4658 | }); |
| 4659 | } finally { |
| 4660 | Binder.restoreCallingIdentity(token); |
| 4661 | } |
| 4662 | } |
| 4663 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4664 | public void setImsRegistrationState(boolean registered) { |
| 4665 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4666 | |
| 4667 | final long identity = Binder.clearCallingIdentity(); |
| 4668 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4669 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4670 | } finally { |
| 4671 | Binder.restoreCallingIdentity(identity); |
| 4672 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4676 | * Set the network selection mode to automatic. |
| 4677 | * |
| 4678 | */ |
| 4679 | @Override |
| 4680 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4681 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4682 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4684 | if (!isActiveSubscription(subId)) { |
| 4685 | return; |
| 4686 | } |
| 4687 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4688 | final long identity = Binder.clearCallingIdentity(); |
| 4689 | try { |
| 4690 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4691 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4692 | } finally { |
| 4693 | Binder.restoreCallingIdentity(identity); |
| 4694 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4695 | } |
| 4696 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4697 | /** |
| 4698 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4699 | * |
| 4700 | * @param subId the id of the subscription. |
| 4701 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4702 | * the operator to attach to. |
| 4703 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4704 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4705 | * normal network selection next time. |
| 4706 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4707 | */ |
| 4708 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4709 | public boolean setNetworkSelectionModeManual( |
| 4710 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4712 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4713 | |
| 4714 | if (!isActiveSubscription(subId)) { |
| 4715 | return false; |
| 4716 | } |
| 4717 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4718 | final long identity = Binder.clearCallingIdentity(); |
| 4719 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4720 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4721 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4722 | if (DBG) { |
| 4723 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4724 | + " operator: " + operatorInfo); |
| 4725 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4726 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4727 | } finally { |
| 4728 | Binder.restoreCallingIdentity(identity); |
| 4729 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * Scans for available networks. |
| 4734 | */ |
| 4735 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4736 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4738 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4739 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4740 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4741 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4742 | .setCallingPackage(callingPackage) |
| 4743 | .setCallingPid(Binder.getCallingPid()) |
| 4744 | .setCallingUid(Binder.getCallingUid()) |
| 4745 | .setMethod("getCellNetworkScanResults") |
| 4746 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4747 | .build()); |
| 4748 | switch (locationResult) { |
| 4749 | case DENIED_HARD: |
| 4750 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4751 | case DENIED_SOFT: |
| 4752 | return null; |
| 4753 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4754 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4755 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4756 | try { |
| 4757 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4758 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4759 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4760 | } finally { |
| 4761 | Binder.restoreCallingIdentity(identity); |
| 4762 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4766 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4767 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4768 | * @param subId id of the subscription |
| 4769 | * @param request contains the radio access networks with bands/channels to scan |
| 4770 | * @param messenger callback messenger for scan results or errors |
| 4771 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4772 | * @return the id of the requested scan which can be used to stop the scan. |
| 4773 | */ |
| 4774 | @Override |
| 4775 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4776 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4777 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4778 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4779 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4780 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4781 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4782 | .setCallingPackage(callingPackage) |
| 4783 | .setCallingPid(Binder.getCallingPid()) |
| 4784 | .setCallingUid(Binder.getCallingUid()) |
| 4785 | .setMethod("requestNetworkScan") |
| 4786 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4787 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4788 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4789 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4790 | if (e != null) { |
| 4791 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4792 | throw e; |
| 4793 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4794 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4795 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4796 | } |
| 4797 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4798 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4799 | int callingUid = Binder.getCallingUid(); |
| 4800 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4801 | final long identity = Binder.clearCallingIdentity(); |
| 4802 | try { |
| 4803 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4804 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4805 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4806 | } finally { |
| 4807 | Binder.restoreCallingIdentity(identity); |
| 4808 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4809 | } |
| 4810 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4811 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4812 | NetworkScanRequest request, int subId) { |
| 4813 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4814 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4815 | boolean hasNetworkScanPermission = |
| 4816 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4817 | == PERMISSION_GRANTED; |
| 4818 | |
| 4819 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4820 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4821 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4825 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4826 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4827 | return new SecurityException("Specific channels must not be" |
| 4828 | + " scanned without location access."); |
| 4829 | } |
| 4830 | } |
| 4831 | } |
| 4832 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4833 | return null; |
| 4834 | } |
| 4835 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4836 | /** |
| 4837 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4838 | * |
| 4839 | * @param subId id of the subscription |
| 4840 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4841 | */ |
| 4842 | @Override |
| 4843 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4844 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4845 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4846 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4847 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4848 | final long identity = Binder.clearCallingIdentity(); |
| 4849 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4850 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4851 | } finally { |
| 4852 | Binder.restoreCallingIdentity(identity); |
| 4853 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4857 | * Get the calculated preferred network type. |
| 4858 | * Used for debugging incorrect network type. |
| 4859 | * |
| 4860 | * @return the preferred network type, defined in RILConstants.java. |
| 4861 | */ |
| 4862 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4863 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4864 | final Phone defaultPhone = getDefaultPhone(); |
| 4865 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4866 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4867 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4868 | } |
| 4869 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4870 | final long identity = Binder.clearCallingIdentity(); |
| 4871 | try { |
| 4872 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4873 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | } finally { |
| 4875 | Binder.restoreCallingIdentity(identity); |
| 4876 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4880 | * Get the preferred network type. |
| 4881 | * Used for device configuration by some CDMA operators. |
| 4882 | * |
| 4883 | * @return the preferred network type, defined in RILConstants.java. |
| 4884 | */ |
| 4885 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4886 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4887 | TelephonyPermissions |
| 4888 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4889 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4890 | |
| 4891 | final long identity = Binder.clearCallingIdentity(); |
| 4892 | try { |
| 4893 | if (DBG) log("getPreferredNetworkType"); |
| 4894 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4895 | int networkType = (result != null ? result[0] : -1); |
| 4896 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4897 | return networkType; |
| 4898 | } finally { |
| 4899 | Binder.restoreCallingIdentity(identity); |
| 4900 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4901 | } |
| 4902 | |
| 4903 | /** |
| 4904 | * Set the preferred network type. |
| 4905 | * Used for device configuration by some CDMA operators. |
| 4906 | * |
| 4907 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4908 | * @return true on success; false on any failure. |
| 4909 | */ |
| 4910 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4911 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4913 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4914 | |
| 4915 | final long identity = Binder.clearCallingIdentity(); |
| 4916 | try { |
| 4917 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4918 | Boolean success = (Boolean) sendRequest( |
| 4919 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4920 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4921 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4922 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4923 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4924 | } |
| 4925 | return success; |
| 4926 | } finally { |
| 4927 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4928 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4929 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4930 | |
| 4931 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4932 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4933 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4934 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4935 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4936 | * @hide |
| 4937 | */ |
| 4938 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 4939 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4940 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4941 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4942 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4944 | if (phone != null) { |
| 4945 | return phone.hasMatchedTetherApnSetting(); |
| 4946 | } else { |
| 4947 | return false; |
| 4948 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4949 | } finally { |
| 4950 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4951 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4952 | } |
| 4953 | |
| 4954 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4955 | * Set mobile data enabled |
| 4956 | * Used by the user through settings etc to turn on/off mobile data |
| 4957 | * |
| 4958 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4959 | */ |
| 4960 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4961 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4962 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4963 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4964 | |
| 4965 | final long identity = Binder.clearCallingIdentity(); |
| 4966 | try { |
| 4967 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4968 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4969 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4970 | if (phone != null) { |
| 4971 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4972 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4973 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4974 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | } |
| 4976 | } finally { |
| 4977 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4978 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4982 | * Get the user enabled state of Mobile Data. |
| 4983 | * |
| 4984 | * TODO: remove and use isUserDataEnabled. |
| 4985 | * This can't be removed now because some vendor codes |
| 4986 | * calls through ITelephony directly while they should |
| 4987 | * use TelephonyManager. |
| 4988 | * |
| 4989 | * @return true on enabled |
| 4990 | */ |
| 4991 | @Override |
| 4992 | public boolean getDataEnabled(int subId) { |
| 4993 | return isUserDataEnabled(subId); |
| 4994 | } |
| 4995 | |
| 4996 | /** |
| 4997 | * Get whether mobile data is enabled per user setting. |
| 4998 | * |
| 4999 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5000 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5001 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5002 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5003 | * |
| 5004 | * @return {@code true} if data is enabled else {@code false} |
| 5005 | */ |
| 5006 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5007 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5008 | try { |
| 5009 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5010 | null); |
| 5011 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5013 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5014 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5015 | |
| 5016 | final long identity = Binder.clearCallingIdentity(); |
| 5017 | try { |
| 5018 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5019 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5020 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5021 | if (phone != null) { |
| 5022 | boolean retVal = phone.isUserDataEnabled(); |
| 5023 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5024 | return retVal; |
| 5025 | } else { |
| 5026 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5027 | return false; |
| 5028 | } |
| 5029 | } finally { |
| 5030 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5031 | } |
| 5032 | } |
| 5033 | |
| 5034 | /** |
| 5035 | * Get whether mobile data is enabled. |
| 5036 | * |
| 5037 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 5038 | * whether mobile data is actually enabled. |
| 5039 | * |
| 5040 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 5041 | * |
| 5042 | * @return {@code true} if data is enabled else {@code false} |
| 5043 | */ |
| 5044 | @Override |
| 5045 | public boolean isDataEnabled(int subId) { |
| 5046 | try { |
| 5047 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5048 | null); |
| 5049 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5050 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5051 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5052 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5053 | |
| 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
| 5056 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5057 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5058 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5059 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5060 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5061 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5062 | return retVal; |
| 5063 | } else { |
| 5064 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5065 | return false; |
| 5066 | } |
| 5067 | } finally { |
| 5068 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5069 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5070 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5071 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5072 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5073 | Phone phone) { |
| 5074 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5075 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5076 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5077 | || subController == null) return privilegeFromSim; |
| 5078 | |
| 5079 | int uid = Binder.getCallingUid(); |
| 5080 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5081 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5082 | |
| 5083 | final long identity = Binder.clearCallingIdentity(); |
| 5084 | try { |
| 5085 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5086 | SubscriptionManager subManager = (SubscriptionManager) |
| 5087 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5088 | for (String pkg : packages) { |
| 5089 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5090 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5091 | } |
| 5092 | } |
| 5093 | return privilegeFromSim; |
| 5094 | } finally { |
| 5095 | Binder.restoreCallingIdentity(identity); |
| 5096 | } |
| 5097 | } |
| 5098 | |
| 5099 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5100 | String pkgName) { |
| 5101 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5102 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5103 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5104 | || subController == null) return privilegeFromSim; |
| 5105 | |
| 5106 | final long identity = Binder.clearCallingIdentity(); |
| 5107 | try { |
| 5108 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5109 | SubscriptionManager subManager = (SubscriptionManager) |
| 5110 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5111 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5112 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5113 | } finally { |
| 5114 | Binder.restoreCallingIdentity(identity); |
| 5115 | } |
| 5116 | } |
| 5117 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5118 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5119 | public int getCarrierPrivilegeStatus(int subId) { |
| 5120 | final Phone phone = getPhone(subId); |
| 5121 | if (phone == null) { |
| 5122 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5123 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5124 | } |
| 5125 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5126 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5127 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5128 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5129 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5130 | |
| 5131 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5132 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5133 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5134 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5135 | |
| 5136 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5137 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 5138 | final Phone phone = getPhone(subId); |
| 5139 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5140 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5141 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5142 | } |
| 5143 | UiccProfile profile = |
| 5144 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5145 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5146 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5147 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5148 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5149 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5150 | profile.getCarrierPrivilegeStatusForUid( |
| 5151 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5155 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5156 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5157 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5161 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5162 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5163 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5164 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5165 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5166 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5167 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5168 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | @Override |
| 5172 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5173 | if (TextUtils.isEmpty(pkgName)) |
| 5174 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5175 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5176 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5177 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5178 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5179 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5180 | continue; |
| 5181 | } |
| 5182 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5183 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5184 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5185 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5186 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5187 | break; |
| 5188 | } |
| 5189 | } |
| 5190 | |
| 5191 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5192 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5193 | |
| 5194 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5195 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5196 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5197 | loge("phoneId " + phoneId + " is not valid."); |
| 5198 | return null; |
| 5199 | } |
| 5200 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5201 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5202 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5203 | return null ; |
| 5204 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5205 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5206 | } |
| 5207 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5208 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5209 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5210 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5211 | List<String> privilegedPackages = new ArrayList<>(); |
| 5212 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5213 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5214 | // has UICC in that slot. |
| 5215 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5216 | if (card.hasCarrierPrivilegeRules()) { |
| 5217 | if (packages == null) { |
| 5218 | // Only check packages in user 0 for now |
| 5219 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5220 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5221 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5222 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5223 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5224 | } |
| 5225 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5226 | PackageInfo pkgInfo = packages.get(p); |
| 5227 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5228 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5229 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5230 | privilegedPackages.add(pkgInfo.packageName); |
| 5231 | } |
| 5232 | } |
| 5233 | } |
| 5234 | } |
| 5235 | return privilegedPackages; |
| 5236 | } |
| 5237 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5238 | @Override |
| 5239 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 5240 | List<String> privilegedPackages = new ArrayList<>(); |
| 5241 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5242 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5243 | } |
| 5244 | return privilegedPackages; |
| 5245 | } |
| 5246 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5247 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5248 | final Phone phone = getPhone(subId); |
| 5249 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5250 | if (card == null) { |
| 5251 | loge("getIccId: No UICC"); |
| 5252 | return null; |
| 5253 | } |
| 5254 | String iccId = card.getIccId(); |
| 5255 | if (TextUtils.isEmpty(iccId)) { |
| 5256 | loge("getIccId: ICC ID is null or empty."); |
| 5257 | return null; |
| 5258 | } |
| 5259 | return iccId; |
| 5260 | } |
| 5261 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5262 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5263 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5264 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5265 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5266 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5267 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | final long identity = Binder.clearCallingIdentity(); |
| 5269 | try { |
| 5270 | final String iccId = getIccId(subId); |
| 5271 | final Phone phone = getPhone(subId); |
| 5272 | if (phone == null) { |
| 5273 | return false; |
| 5274 | } |
| 5275 | final String subscriberId = phone.getSubscriberId(); |
| 5276 | |
| 5277 | if (DBG_MERGE) { |
| 5278 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5279 | + subscriberId + " to " + number); |
| 5280 | } |
| 5281 | |
| 5282 | if (TextUtils.isEmpty(iccId)) { |
| 5283 | return false; |
| 5284 | } |
| 5285 | |
| 5286 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5287 | |
| 5288 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5289 | if (alphaTag == null) { |
| 5290 | editor.remove(alphaTagPrefKey); |
| 5291 | } else { |
| 5292 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5293 | } |
| 5294 | |
| 5295 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5296 | // track all merged IMSIs based on line number |
| 5297 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5298 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5299 | if (number == null) { |
| 5300 | editor.remove(numberPrefKey); |
| 5301 | editor.remove(subscriberPrefKey); |
| 5302 | } else { |
| 5303 | editor.putString(numberPrefKey, number); |
| 5304 | editor.putString(subscriberPrefKey, subscriberId); |
| 5305 | } |
| 5306 | |
| 5307 | editor.commit(); |
| 5308 | return true; |
| 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5311 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5315 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5316 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5317 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5318 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5319 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5320 | return null; |
| 5321 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5322 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5323 | final long identity = Binder.clearCallingIdentity(); |
| 5324 | try { |
| 5325 | String iccId = getIccId(subId); |
| 5326 | if (iccId != null) { |
| 5327 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5328 | if (DBG_MERGE) { |
| 5329 | log("getLine1NumberForDisplay returning " |
| 5330 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5331 | } |
| 5332 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5333 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5335 | return null; |
| 5336 | } finally { |
| 5337 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5338 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5342 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5343 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5344 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5345 | return null; |
| 5346 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5347 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5348 | final long identity = Binder.clearCallingIdentity(); |
| 5349 | try { |
| 5350 | String iccId = getIccId(subId); |
| 5351 | if (iccId != null) { |
| 5352 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5353 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5354 | } |
| 5355 | return null; |
| 5356 | } finally { |
| 5357 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5358 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5359 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5360 | |
| 5361 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5362 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5363 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5364 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5365 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5366 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5367 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5368 | return null; |
| 5369 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5370 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5371 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5372 | // the process, where TelephonyManager was instantiated. |
| 5373 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5374 | final long identity = Binder.clearCallingIdentity(); |
| 5375 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5376 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5377 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5378 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5379 | |
| 5380 | // Figure out what subscribers are currently active |
| 5381 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5382 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5383 | // Only consider subs which match the current subId |
| 5384 | // This logic can be simplified. See b/131189269 for progress. |
| 5385 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5386 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5387 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5388 | |
| 5389 | // First pass, find a number override for an active subscriber |
| 5390 | String mergeNumber = null; |
| 5391 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5392 | for (String key : prefs.keySet()) { |
| 5393 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5394 | final String subscriberId = (String) prefs.get(key); |
| 5395 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5396 | final String iccId = key.substring( |
| 5397 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5398 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5399 | mergeNumber = (String) prefs.get(numberKey); |
| 5400 | if (DBG_MERGE) { |
| 5401 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5402 | + " for active subscriber " + subscriberId); |
| 5403 | } |
| 5404 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5405 | break; |
| 5406 | } |
| 5407 | } |
| 5408 | } |
| 5409 | } |
| 5410 | |
| 5411 | // Shortcut when no active merged subscribers |
| 5412 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5413 | return null; |
| 5414 | } |
| 5415 | |
| 5416 | // Second pass, find all subscribers under that line override |
| 5417 | final ArraySet<String> result = new ArraySet<>(); |
| 5418 | for (String key : prefs.keySet()) { |
| 5419 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5420 | final String number = (String) prefs.get(key); |
| 5421 | if (mergeNumber.equals(number)) { |
| 5422 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5423 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5424 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5425 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5426 | result.add(subscriberId); |
| 5427 | } |
| 5428 | } |
| 5429 | } |
| 5430 | } |
| 5431 | |
| 5432 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5433 | Arrays.sort(resultArray); |
| 5434 | if (DBG_MERGE) { |
| 5435 | Slog.d(LOG_TAG, |
| 5436 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5437 | } |
| 5438 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5439 | } finally { |
| 5440 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5441 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5445 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5446 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5447 | |
| 5448 | final long identity = Binder.clearCallingIdentity(); |
| 5449 | try { |
| 5450 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5451 | TelephonyManager.class); |
| 5452 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5453 | if (subscriberId == null) { |
| 5454 | if (DBG) { |
| 5455 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5456 | + subId); |
| 5457 | } |
| 5458 | return null; |
| 5459 | } |
| 5460 | |
| 5461 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5462 | .getSubscriptionInfo(subId); |
| 5463 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5464 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5465 | if (groupUuid == null) { |
| 5466 | return new String[]{subscriberId}; |
| 5467 | } |
| 5468 | |
| 5469 | // Get all subscriberIds from the group. |
| 5470 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5471 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5472 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5473 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5474 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5475 | if (subscriberId != null) { |
| 5476 | mergedSubscriberIds.add(subscriberId); |
| 5477 | } |
| 5478 | } |
| 5479 | |
| 5480 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5481 | } finally { |
| 5482 | Binder.restoreCallingIdentity(identity); |
| 5483 | |
| 5484 | } |
| 5485 | } |
| 5486 | |
| 5487 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5488 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5489 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5490 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 | |
| 5492 | final long identity = Binder.clearCallingIdentity(); |
| 5493 | try { |
| 5494 | final Phone phone = getPhone(subId); |
| 5495 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5496 | } finally { |
| 5497 | Binder.restoreCallingIdentity(identity); |
| 5498 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5499 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5500 | |
| 5501 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5502 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5503 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5504 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5505 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | |
| 5507 | final long identity = Binder.clearCallingIdentity(); |
| 5508 | try { |
| 5509 | final Phone phone = getPhone(subId); |
| 5510 | if (phone == null) { |
| 5511 | return false; |
| 5512 | } |
| 5513 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5514 | cdmaNonRoamingList); |
| 5515 | } finally { |
| 5516 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5517 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5518 | } |
| 5519 | |
| 5520 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5521 | @Deprecated |
| 5522 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5523 | enforceModifyPermission(); |
| 5524 | |
| 5525 | int returnValue = 0; |
| 5526 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5527 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5528 | if(result.exception == null) { |
| 5529 | if (result.result != null) { |
| 5530 | byte[] responseData = (byte[])(result.result); |
| 5531 | if(responseData.length > oemResp.length) { |
| 5532 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5533 | responseData.length + "bytes. Buffer Size is " + |
| 5534 | oemResp.length + "bytes."); |
| 5535 | } |
| 5536 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5537 | returnValue = responseData.length; |
| 5538 | } |
| 5539 | } else { |
| 5540 | CommandException ex = (CommandException) result.exception; |
| 5541 | returnValue = ex.getCommandError().ordinal(); |
| 5542 | if(returnValue > 0) returnValue *= -1; |
| 5543 | } |
| 5544 | } catch (RuntimeException e) { |
| 5545 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5546 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5547 | if(returnValue > 0) returnValue *= -1; |
| 5548 | } |
| 5549 | |
| 5550 | return returnValue; |
| 5551 | } |
| 5552 | |
| 5553 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5554 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5555 | try { |
| 5556 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5557 | } catch (RuntimeException e) { |
| 5558 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5559 | } |
| 5560 | } |
| 5561 | |
| 5562 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5563 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5564 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5565 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5566 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5567 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5568 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | final long identity = Binder.clearCallingIdentity(); |
| 5570 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5571 | TelephonyPermissions |
| 5572 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5573 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5574 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5575 | } finally { |
| 5576 | Binder.restoreCallingIdentity(identity); |
| 5577 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5578 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5579 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5580 | |
| 5581 | @Override |
| 5582 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5583 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5584 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5585 | |
| 5586 | final long identity = Binder.clearCallingIdentity(); |
| 5587 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5588 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5589 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | } finally { |
| 5591 | Binder.restoreCallingIdentity(identity); |
| 5592 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5596 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5597 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5598 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5599 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5600 | return false; |
| 5601 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5602 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5603 | final long identity = Binder.clearCallingIdentity(); |
| 5604 | try { |
| 5605 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5606 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5607 | // In the long run, we may instead need to check if there exists a connection service |
| 5608 | // which can support video calling. |
| 5609 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5610 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | return imsManager.isVtEnabledByPlatform() |
| 5612 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5613 | && imsManager.isVtEnabledByUser(); |
| 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
| 5616 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5617 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5618 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5619 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5620 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5621 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5622 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5623 | return false; |
| 5624 | } |
| 5625 | |
| 5626 | final long identity = Binder.clearCallingIdentity(); |
| 5627 | try { |
| 5628 | CarrierConfigManager configManager = |
| 5629 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5630 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5631 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5632 | } finally { |
| 5633 | Binder.restoreCallingIdentity(identity); |
| 5634 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5638 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5639 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5640 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5641 | return false; |
| 5642 | } |
| 5643 | |
| 5644 | final long identity = Binder.clearCallingIdentity(); |
| 5645 | try { |
| 5646 | CarrierConfigManager configManager = |
| 5647 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5648 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5650 | } finally { |
| 5651 | Binder.restoreCallingIdentity(identity); |
| 5652 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5653 | } |
| 5654 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5655 | @Override |
| 5656 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 5657 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5658 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | @Override |
| 5662 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5663 | final long identity = Binder.clearCallingIdentity(); |
| 5664 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5665 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
| 5668 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5671 | /** |
| 5672 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5673 | * support for the feature and device firmware support. |
| 5674 | * |
| 5675 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5676 | */ |
| 5677 | @Override |
| 5678 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5679 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5680 | final Phone phone = getPhone(subscriptionId); |
| 5681 | if (phone == null) { |
| 5682 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5683 | return false; |
| 5684 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5685 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5686 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5687 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5688 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5689 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5690 | return isCarrierSupported && isDeviceSupported; |
| 5691 | } finally { |
| 5692 | Binder.restoreCallingIdentity(identity); |
| 5693 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5694 | } |
| 5695 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5696 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5697 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5698 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5699 | * 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] | 5700 | */ |
| 5701 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | final long identity = Binder.clearCallingIdentity(); |
| 5703 | try { |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5704 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5705 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5706 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5707 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5708 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5709 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | } finally { |
| 5711 | Binder.restoreCallingIdentity(identity); |
| 5712 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5713 | } |
| 5714 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5715 | /** |
| 5716 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5717 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5718 | * |
| 5719 | * <p>Requires Permission: |
| 5720 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5721 | */ |
| 5722 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5723 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5724 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5725 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5726 | return null; |
| 5727 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5728 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5729 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5730 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5731 | return null; |
| 5732 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | |
| 5734 | final long identity = Binder.clearCallingIdentity(); |
| 5735 | try { |
| 5736 | return phone.getDeviceId(); |
| 5737 | } finally { |
| 5738 | Binder.restoreCallingIdentity(identity); |
| 5739 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5740 | } |
| 5741 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5742 | /** |
| 5743 | * {@hide} |
| 5744 | * Returns the IMS Registration Status on a particular subid |
| 5745 | * |
| 5746 | * @param subId |
| 5747 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5748 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5749 | Phone phone = getPhone(subId); |
| 5750 | if (phone != null) { |
| 5751 | return phone.isImsRegistered(); |
| 5752 | } else { |
| 5753 | return false; |
| 5754 | } |
| 5755 | } |
| 5756 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5757 | @Override |
| 5758 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5759 | final long identity = Binder.clearCallingIdentity(); |
| 5760 | try { |
| 5761 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5762 | } finally { |
| 5763 | Binder.restoreCallingIdentity(identity); |
| 5764 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5765 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5766 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5767 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5768 | public int getSubIdForPhoneAccountHandle( |
| 5769 | PhoneAccountHandle phoneAccountHandle, String callingPackage) { |
| 5770 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
| 5771 | callingPackage, "getSubIdForPhoneAccountHandle")) { |
| 5772 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 5773 | } |
| 5774 | final long identity = Binder.clearCallingIdentity(); |
| 5775 | try { |
| 5776 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 5777 | } finally { |
| 5778 | Binder.restoreCallingIdentity(identity); |
| 5779 | } |
| 5780 | } |
| 5781 | |
| 5782 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5783 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5784 | final long identity = Binder.clearCallingIdentity(); |
| 5785 | try { |
| 5786 | Phone phone = getPhone(subscriptionId); |
| 5787 | if (phone == null) { |
| 5788 | return null; |
| 5789 | } |
| 5790 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5791 | } finally { |
| 5792 | Binder.restoreCallingIdentity(identity); |
| 5793 | } |
| 5794 | } |
| 5795 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5796 | /** |
| 5797 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5798 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5799 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5800 | final long identity = Binder.clearCallingIdentity(); |
| 5801 | try { |
| 5802 | Phone phone = getPhone(subId); |
| 5803 | if (phone != null) { |
| 5804 | return phone.isWifiCallingEnabled(); |
| 5805 | } else { |
| 5806 | return false; |
| 5807 | } |
| 5808 | } finally { |
| 5809 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5810 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5813 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5814 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5815 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5816 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5817 | final long identity = Binder.clearCallingIdentity(); |
| 5818 | try { |
| 5819 | Phone phone = getPhone(subId); |
| 5820 | if (phone != null) { |
| 5821 | return phone.isVideoEnabled(); |
| 5822 | } else { |
| 5823 | return false; |
| 5824 | } |
| 5825 | } finally { |
| 5826 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5827 | } |
| 5828 | } |
| 5829 | |
| 5830 | /** |
| 5831 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5832 | * defined in {@link ImsRegistrationImplBase}. |
| 5833 | */ |
| 5834 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5835 | final long identity = Binder.clearCallingIdentity(); |
| 5836 | try { |
| 5837 | Phone phone = getPhone(subId); |
| 5838 | if (phone != null) { |
| 5839 | return phone.getImsRegistrationTech(); |
| 5840 | } else { |
| 5841 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5842 | } |
| 5843 | } finally { |
| 5844 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5845 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5846 | } |
| 5847 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5848 | @Override |
| 5849 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 5850 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5851 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5852 | return; |
| 5853 | } |
| 5854 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5855 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5856 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5857 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5858 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5859 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5860 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5861 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5862 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5863 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5864 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5865 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5866 | // There has been issues when Sms raw table somehow stores orphan |
| 5867 | // fragments. They lead to garbled message when new fragments come |
| 5868 | // in and combined with those stale ones. In case this happens again, |
| 5869 | // user can reset all network settings which will clean up this table. |
| 5870 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5871 | // Clean up IMS settings as well here. |
| 5872 | int slotId = getSlotIndex(subId); |
| 5873 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5874 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 5875 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 5876 | |
| 5877 | // Erase modem config if erase modem on network setting is enabled. |
| 5878 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 5879 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 5880 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 5881 | sendEraseModemConfig(getDefaultPhone()); |
| 5882 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5883 | } finally { |
| 5884 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5885 | } |
| 5886 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5887 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5888 | private void cleanUpSmsRawTable(Context context) { |
| 5889 | ContentResolver resolver = context.getContentResolver(); |
| 5890 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5891 | resolver.delete(uri, null, null); |
| 5892 | } |
| 5893 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5894 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5895 | public String getSimLocaleForSubscriber(int subId) { |
| 5896 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5897 | final Phone phone = getPhone(subId); |
| 5898 | if (phone == null) { |
| 5899 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5900 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5901 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5902 | final long identity = Binder.clearCallingIdentity(); |
| 5903 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5904 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5905 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5906 | if (info == null) { |
| 5907 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5908 | return null; |
| 5909 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5910 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5911 | // preferences (EF-PL and EF-LI)... |
| 5912 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5913 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5914 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5915 | if (localeFromDefaultSim != null) { |
| 5916 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5917 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5918 | + localeFromDefaultSim); |
| 5919 | return localeFromDefaultSim.toLanguageTag(); |
| 5920 | } else { |
| 5921 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5922 | } |
| 5923 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5924 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5926 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5927 | // the SIM and carrier preferences does not include a country we add the country |
| 5928 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5929 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5930 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5931 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5932 | return mccLocale.toLanguageTag(); |
| 5933 | } |
| 5934 | |
| 5935 | if (DBG) log("No locale found - returning null"); |
| 5936 | return null; |
| 5937 | } finally { |
| 5938 | Binder.restoreCallingIdentity(identity); |
| 5939 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5943 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5944 | } |
| 5945 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | /** |
| 5947 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5948 | */ |
| 5949 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5950 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5951 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5952 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5953 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5954 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5955 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5956 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5957 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5958 | * representing the state of the modem. |
| 5959 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5960 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5961 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5962 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5963 | */ |
| 5964 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5965 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5966 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5967 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5968 | |
| 5969 | final long identity = Binder.clearCallingIdentity(); |
| 5970 | try { |
| 5971 | ModemActivityInfo ret = null; |
| 5972 | synchronized (mLastModemActivityInfo) { |
| 5973 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5974 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5975 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5976 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5977 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5978 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5979 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5980 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | } |
| 5982 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5983 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5984 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5985 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5986 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5987 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5988 | mLastModemActivityInfo.setRxTimeMillis( |
| 5989 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5990 | mLastModemActivityInfo.setEnergyUsed( |
| 5991 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5992 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5993 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5994 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5995 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5996 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5997 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5998 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5999 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | Bundle bundle = new Bundle(); |
| 6001 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6002 | result.send(0, bundle); |
| 6003 | } finally { |
| 6004 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6005 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6006 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6007 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6008 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6009 | // less than total activity duration. |
| 6010 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6011 | if (info == null) { |
| 6012 | return false; |
| 6013 | } |
| 6014 | int activityDurationMs = |
| 6015 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6016 | int totalTxTimeMs = 0; |
| 6017 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 6018 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 6019 | } |
| 6020 | return (info.isValid() |
| 6021 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6022 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 6023 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 6024 | && (totalTxTimeMs <= activityDurationMs)); |
| 6025 | } |
| 6026 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6027 | /** |
| 6028 | * {@hide} |
| 6029 | * Returns the service state information on specified subscription. |
| 6030 | */ |
| 6031 | @Override |
| 6032 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6033 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6034 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6035 | return null; |
| 6036 | } |
| 6037 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6038 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6039 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6040 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6041 | .setCallingPackage(callingPackage) |
| 6042 | .setCallingPid(Binder.getCallingPid()) |
| 6043 | .setCallingUid(Binder.getCallingUid()) |
| 6044 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6045 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6046 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6047 | .build()); |
| 6048 | |
| 6049 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6050 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6051 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6052 | .setCallingPackage(callingPackage) |
| 6053 | .setCallingPid(Binder.getCallingPid()) |
| 6054 | .setCallingUid(Binder.getCallingUid()) |
| 6055 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6056 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6057 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6058 | .build()); |
| 6059 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6060 | boolean hasFinePermission = |
| 6061 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6062 | boolean hasCoarsePermission = |
| 6063 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6064 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6065 | final long identity = Binder.clearCallingIdentity(); |
| 6066 | try { |
| 6067 | final Phone phone = getPhone(subId); |
| 6068 | if (phone == null) { |
| 6069 | return null; |
| 6070 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6071 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6072 | ServiceState ss = phone.getServiceState(); |
| 6073 | |
| 6074 | // Scrub out the location info in ServiceState depending on what level of access |
| 6075 | // the caller has. |
| 6076 | if (hasFinePermission) return ss; |
| 6077 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 6078 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6079 | } finally { |
| 6080 | Binder.restoreCallingIdentity(identity); |
| 6081 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6082 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6083 | |
| 6084 | /** |
| 6085 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6086 | * |
| 6087 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6088 | * voicemail ringtone. |
| 6089 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6090 | * PhoneAccount. |
| 6091 | */ |
| 6092 | @Override |
| 6093 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | final long identity = Binder.clearCallingIdentity(); |
| 6095 | try { |
| 6096 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6097 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6098 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6099 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6100 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6101 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6102 | } finally { |
| 6103 | Binder.restoreCallingIdentity(identity); |
| 6104 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6108 | * Sets the per-account voicemail ringtone. |
| 6109 | * |
| 6110 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6111 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6112 | * |
| 6113 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6114 | * voicemail ringtone. |
| 6115 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6116 | * PhoneAccount. |
| 6117 | */ |
| 6118 | @Override |
| 6119 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6120 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6121 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6122 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6123 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6124 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6125 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6126 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6127 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6128 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | |
| 6130 | final long identity = Binder.clearCallingIdentity(); |
| 6131 | try { |
| 6132 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6133 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6134 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | } |
| 6136 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6137 | } finally { |
| 6138 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6139 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6143 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6144 | * |
| 6145 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6146 | * voicemail vibration setting. |
| 6147 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6148 | */ |
| 6149 | @Override |
| 6150 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | final long identity = Binder.clearCallingIdentity(); |
| 6152 | try { |
| 6153 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6154 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6155 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6156 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6157 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6159 | } finally { |
| 6160 | Binder.restoreCallingIdentity(identity); |
| 6161 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6162 | } |
| 6163 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6164 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6165 | * Sets the per-account voicemail vibration. |
| 6166 | * |
| 6167 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6168 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6169 | * |
| 6170 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6171 | * voicemail vibration setting. |
| 6172 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6173 | * specific PhoneAccount. |
| 6174 | */ |
| 6175 | @Override |
| 6176 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6177 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6178 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6179 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6180 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6181 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6182 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6183 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6184 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6185 | } |
| 6186 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6187 | final long identity = Binder.clearCallingIdentity(); |
| 6188 | try { |
| 6189 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6190 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6191 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6192 | } |
| 6193 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6194 | } finally { |
| 6195 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6196 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6197 | } |
| 6198 | |
| 6199 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6200 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6201 | * |
| 6202 | * @throws SecurityException if the caller does not have the required permission |
| 6203 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6204 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6205 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6206 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6207 | } |
| 6208 | |
| 6209 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6210 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6211 | * permission. |
| 6212 | * |
| 6213 | * @throws SecurityException if the caller does not have the required permission |
| 6214 | */ |
| 6215 | private void enforceSendSmsPermission() { |
| 6216 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6217 | } |
| 6218 | |
| 6219 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6220 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6221 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6222 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6223 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6224 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6225 | final long identity = Binder.clearCallingIdentity(); |
| 6226 | try { |
| 6227 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6228 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6229 | if (componentName == null) { |
| 6230 | throw new SecurityException( |
| 6231 | "Caller not current active visual voicemail package[null]"); |
| 6232 | } |
| 6233 | String vvmPackage = componentName.getPackageName(); |
| 6234 | if (!callingPackage.equals(vvmPackage)) { |
| 6235 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6236 | + vvmPackage + "]"); |
| 6237 | } |
| 6238 | } finally { |
| 6239 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6240 | } |
| 6241 | } |
| 6242 | |
| 6243 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6244 | * Return the application ID for the app type. |
| 6245 | * |
| 6246 | * @param subId the subscription ID that this request applies to. |
| 6247 | * @param appType the uicc app type. |
| 6248 | * @return Application ID for specificied app type, or null if no uicc. |
| 6249 | */ |
| 6250 | @Override |
| 6251 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6252 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6253 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6254 | |
| 6255 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6256 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6257 | if (phone == null) { |
| 6258 | return null; |
| 6259 | } |
| 6260 | String aid = null; |
| 6261 | try { |
| 6262 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6263 | .getApplicationByType(appType).getAid(); |
| 6264 | } catch (Exception e) { |
| 6265 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6266 | } |
| 6267 | return aid; |
| 6268 | } finally { |
| 6269 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6270 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6271 | } |
| 6272 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6273 | /** |
| 6274 | * Return the Electronic Serial Number. |
| 6275 | * |
| 6276 | * @param subId the subscription ID that this request applies to. |
| 6277 | * @return ESN or null if error. |
| 6278 | */ |
| 6279 | @Override |
| 6280 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6281 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6282 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | |
| 6284 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6285 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | if (phone == null) { |
| 6287 | return null; |
| 6288 | } |
| 6289 | String esn = null; |
| 6290 | try { |
| 6291 | esn = phone.getEsn(); |
| 6292 | } catch (Exception e) { |
| 6293 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6294 | } |
| 6295 | return esn; |
| 6296 | } finally { |
| 6297 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6298 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6299 | } |
| 6300 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6301 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6302 | * Return the Preferred Roaming List Version. |
| 6303 | * |
| 6304 | * @param subId the subscription ID that this request applies to. |
| 6305 | * @return PRLVersion or null if error. |
| 6306 | */ |
| 6307 | @Override |
| 6308 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6309 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6310 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | |
| 6312 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6313 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6314 | if (phone == null) { |
| 6315 | return null; |
| 6316 | } |
| 6317 | String cdmaPrlVersion = null; |
| 6318 | try { |
| 6319 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6320 | } catch (Exception e) { |
| 6321 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6322 | } |
| 6323 | return cdmaPrlVersion; |
| 6324 | } finally { |
| 6325 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6326 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6327 | } |
| 6328 | |
| 6329 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6330 | * Get snapshot of Telephony histograms |
| 6331 | * @return List of Telephony histograms |
| 6332 | * @hide |
| 6333 | */ |
| 6334 | @Override |
| 6335 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6336 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6337 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6338 | |
| 6339 | final long identity = Binder.clearCallingIdentity(); |
| 6340 | try { |
| 6341 | return RIL.getTelephonyRILTimingHistograms(); |
| 6342 | } finally { |
| 6343 | Binder.restoreCallingIdentity(identity); |
| 6344 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6345 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6346 | |
| 6347 | /** |
| 6348 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6349 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6350 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6351 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6352 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6353 | * @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] | 6354 | */ |
| 6355 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6356 | @TelephonyManager.SetCarrierRestrictionResult |
| 6357 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6358 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6359 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6360 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6361 | if (carrierRestrictionRules == null) { |
| 6362 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6363 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6364 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | final long identity = Binder.clearCallingIdentity(); |
| 6366 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6367 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6368 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6369 | } finally { |
| 6370 | Binder.restoreCallingIdentity(identity); |
| 6371 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6372 | } |
| 6373 | |
| 6374 | /** |
| 6375 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6376 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6377 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6378 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6379 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6380 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6381 | */ |
| 6382 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6383 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6384 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6385 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | |
| 6387 | final long identity = Binder.clearCallingIdentity(); |
| 6388 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6389 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6390 | if (response instanceof CarrierRestrictionRules) { |
| 6391 | return (CarrierRestrictionRules) response; |
| 6392 | } |
| 6393 | // Response is an Exception of some kind, |
| 6394 | // which is signalled to the user as a NULL retval |
| 6395 | return null; |
| 6396 | } catch (Exception e) { |
| 6397 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6398 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6399 | } finally { |
| 6400 | Binder.restoreCallingIdentity(identity); |
| 6401 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6402 | } |
| 6403 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6404 | /** |
| 6405 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6406 | * @param subId the subscription ID that this action applies to. |
| 6407 | * @param enabled control enable or disable metered apns. |
| 6408 | * {@hide} |
| 6409 | */ |
| 6410 | @Override |
| 6411 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6412 | enforceModifyPermission(); |
| 6413 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | |
| 6415 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6416 | if (phone == null) { |
| 6417 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6418 | return; |
| 6419 | } |
| 6420 | try { |
| 6421 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6422 | } catch (Exception e) { |
| 6423 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6424 | } finally { |
| 6425 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | /** |
| 6430 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6431 | * @param subId the subscription ID that this action applies to. |
| 6432 | * @param enabled control enable or disable radio. |
| 6433 | * {@hide} |
| 6434 | */ |
| 6435 | @Override |
| 6436 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6437 | enforceModifyPermission(); |
| 6438 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | |
| 6440 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6441 | if (phone == null) { |
| 6442 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6443 | return; |
| 6444 | } |
| 6445 | try { |
| 6446 | phone.carrierActionSetRadioEnabled(enabled); |
| 6447 | } catch (Exception e) { |
| 6448 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6449 | } finally { |
| 6450 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6451 | } |
| 6452 | } |
| 6453 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6454 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6455 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6456 | * network status based on which carrier apps could apply actions accordingly, |
| 6457 | * enable/disable default url handler for example. |
| 6458 | * |
| 6459 | * @param subId the subscription ID that this action applies to. |
| 6460 | * @param report control start/stop reporting the default network status. |
| 6461 | * {@hide} |
| 6462 | */ |
| 6463 | @Override |
| 6464 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6465 | enforceModifyPermission(); |
| 6466 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6467 | |
| 6468 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6469 | if (phone == null) { |
| 6470 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6471 | return; |
| 6472 | } |
| 6473 | try { |
| 6474 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6475 | } catch (Exception e) { |
| 6476 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6477 | } finally { |
| 6478 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6479 | } |
| 6480 | } |
| 6481 | |
| 6482 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6483 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6484 | * @param subId the subscription ID that this action applies to. |
| 6485 | * {@hide} |
| 6486 | */ |
| 6487 | @Override |
| 6488 | public void carrierActionResetAll(int subId) { |
| 6489 | enforceModifyPermission(); |
| 6490 | final Phone phone = getPhone(subId); |
| 6491 | if (phone == null) { |
| 6492 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6493 | return; |
| 6494 | } |
| 6495 | try { |
| 6496 | phone.carrierActionResetAll(); |
| 6497 | } catch (Exception e) { |
| 6498 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6499 | } |
| 6500 | } |
| 6501 | |
| 6502 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6503 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6504 | * bug report is being generated. |
| 6505 | */ |
| 6506 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6507 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6508 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6509 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6510 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6511 | + Binder.getCallingPid() |
| 6512 | + ", uid=" + Binder.getCallingUid() |
| 6513 | + "without permission " |
| 6514 | + android.Manifest.permission.DUMP); |
| 6515 | return; |
| 6516 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6517 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6518 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6519 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6520 | @Override |
| 6521 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6522 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6523 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 6524 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 6525 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6526 | } |
| 6527 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6528 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6529 | * Get aggregated video call data usage since boot. |
| 6530 | * |
| 6531 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6532 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6533 | * {@hide} |
| 6534 | */ |
| 6535 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6536 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6537 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6538 | null); |
| 6539 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6540 | final long identity = Binder.clearCallingIdentity(); |
| 6541 | try { |
| 6542 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6543 | // records the delta with the corresponding network identity. |
| 6544 | // We just return the total video call data usage snapshot since boot. |
| 6545 | Phone phone = getPhone(subId); |
| 6546 | if (phone != null) { |
| 6547 | return phone.getVtDataUsage(perUidStats); |
| 6548 | } |
| 6549 | return null; |
| 6550 | } finally { |
| 6551 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6552 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6553 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6554 | |
| 6555 | /** |
| 6556 | * Policy control of data connection. Usually used when data limit is passed. |
| 6557 | * @param enabled True if enabling the data, otherwise disabling. |
| 6558 | * @param subId Subscription index |
| 6559 | * {@hide} |
| 6560 | */ |
| 6561 | @Override |
| 6562 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6563 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | |
| 6565 | final long identity = Binder.clearCallingIdentity(); |
| 6566 | try { |
| 6567 | Phone phone = getPhone(subId); |
| 6568 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6569 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6570 | } |
| 6571 | } finally { |
| 6572 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6573 | } |
| 6574 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6575 | |
| 6576 | /** |
| 6577 | * Get Client request stats |
| 6578 | * @return List of Client Request Stats |
| 6579 | * @hide |
| 6580 | */ |
| 6581 | @Override |
| 6582 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6584 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6585 | return null; |
| 6586 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6587 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | final long identity = Binder.clearCallingIdentity(); |
| 6590 | try { |
| 6591 | if (phone != null) { |
| 6592 | return phone.getClientRequestStats(); |
| 6593 | } |
| 6594 | |
| 6595 | return null; |
| 6596 | } finally { |
| 6597 | Binder.restoreCallingIdentity(identity); |
| 6598 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6599 | } |
| 6600 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6601 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6602 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6603 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6604 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6605 | |
| 6606 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6607 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6608 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6609 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6610 | * @param state State of SIM (power down, power up, pass through) |
| 6611 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6612 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6613 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6614 | * |
| 6615 | **/ |
| 6616 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6617 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6618 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6619 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6620 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6621 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6622 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6623 | final long identity = Binder.clearCallingIdentity(); |
| 6624 | try { |
| 6625 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6626 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6627 | } |
| 6628 | } finally { |
| 6629 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6630 | } |
| 6631 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6632 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6633 | private boolean isUssdApiAllowed(int subId) { |
| 6634 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6635 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6636 | if (configManager == null) { |
| 6637 | return false; |
| 6638 | } |
| 6639 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6640 | if (pb == null) { |
| 6641 | return false; |
| 6642 | } |
| 6643 | return pb.getBoolean( |
| 6644 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6645 | } |
| 6646 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6647 | /** |
| 6648 | * Check if phone is in emergency callback mode |
| 6649 | * @return true if phone is in emergency callback mode |
| 6650 | * @param subId sub id |
| 6651 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6652 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6653 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6654 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6655 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6656 | |
| 6657 | final long identity = Binder.clearCallingIdentity(); |
| 6658 | try { |
| 6659 | if (phone != null) { |
| 6660 | return phone.isInEcm(); |
| 6661 | } else { |
| 6662 | return false; |
| 6663 | } |
| 6664 | } finally { |
| 6665 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6666 | } |
| 6667 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6668 | |
| 6669 | /** |
| 6670 | * Get the current signal strength information for the given subscription. |
| 6671 | * Because this information is not updated when the device is in a low power state |
| 6672 | * it should not be relied-upon to be current. |
| 6673 | * @param subId Subscription index |
| 6674 | * @return the most recent cached signal strength info from the modem |
| 6675 | */ |
| 6676 | @Override |
| 6677 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6678 | final long identity = Binder.clearCallingIdentity(); |
| 6679 | try { |
| 6680 | Phone p = getPhone(subId); |
| 6681 | if (p == null) { |
| 6682 | return null; |
| 6683 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6684 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6685 | return p.getSignalStrength(); |
| 6686 | } finally { |
| 6687 | Binder.restoreCallingIdentity(identity); |
| 6688 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6689 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6690 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6691 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6692 | * Get the current modem radio state for the given slot. |
| 6693 | * @param slotIndex slot index. |
| 6694 | * @param callingPackage the name of the package making the call. |
| 6695 | * @return the current radio power state from the modem |
| 6696 | */ |
| 6697 | @Override |
| 6698 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6699 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6700 | if (phone != null) { |
| 6701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6702 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6703 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6704 | } |
| 6705 | |
| 6706 | final long identity = Binder.clearCallingIdentity(); |
| 6707 | try { |
| 6708 | return phone.getRadioPowerState(); |
| 6709 | } finally { |
| 6710 | Binder.restoreCallingIdentity(identity); |
| 6711 | } |
| 6712 | } |
| 6713 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6714 | } |
| 6715 | |
| 6716 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6717 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6718 | * |
| 6719 | * <p>Requires one of the following permissions: |
| 6720 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6721 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6722 | * privileges. |
| 6723 | * |
| 6724 | * @param subId subscription id |
| 6725 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6726 | * {@code false}. |
| 6727 | */ |
| 6728 | @Override |
| 6729 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6730 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6731 | null /* message */); |
| 6732 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6733 | boolean isEnabled = false; |
| 6734 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6735 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6736 | Phone phone = getPhone(subId); |
| 6737 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6738 | } catch (Exception e) { |
| 6739 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6740 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6741 | } finally { |
| 6742 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6743 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6744 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6745 | } |
| 6746 | |
| 6747 | |
| 6748 | /** |
| 6749 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6750 | * |
| 6751 | * <p> Requires permission: |
| 6752 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6753 | * privileges. |
| 6754 | * |
| 6755 | * @param subId subscription id |
| 6756 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6757 | */ |
| 6758 | @Override |
| 6759 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6760 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6761 | mApp, subId, "setDataRoamingEnabled"); |
| 6762 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6763 | final long identity = Binder.clearCallingIdentity(); |
| 6764 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6765 | Phone phone = getPhone(subId); |
| 6766 | if (phone != null) { |
| 6767 | phone.setDataRoamingEnabled(isEnabled); |
| 6768 | } |
| 6769 | } finally { |
| 6770 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6771 | } |
| 6772 | } |
| 6773 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6774 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6775 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6776 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6777 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6778 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6779 | boolean isAllowed = true; |
| 6780 | final long identity = Binder.clearCallingIdentity(); |
| 6781 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6782 | Phone phone = getPhone(subId); |
| 6783 | if (phone != null) { |
| 6784 | isAllowed = phone.isCspPlmnEnabled(); |
| 6785 | } |
| 6786 | } finally { |
| 6787 | Binder.restoreCallingIdentity(identity); |
| 6788 | } |
| 6789 | return isAllowed; |
| 6790 | } |
| 6791 | |
| 6792 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6793 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6794 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6795 | try { |
| 6796 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6797 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6798 | } catch (SecurityException e) { |
| 6799 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6800 | // has carrier privileges on an active UICC |
| 6801 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6802 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6803 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6804 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6805 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6806 | |
| 6807 | final long identity = Binder.clearCallingIdentity(); |
| 6808 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6809 | UiccController uiccController = UiccController.getInstance(); |
| 6810 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6811 | if (hasReadPermission) { |
| 6812 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6813 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6814 | |
| 6815 | // Remove private info if the caller doesn't have access |
| 6816 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6817 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6818 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6819 | // is available |
| 6820 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6821 | if (card == null || card.getUiccProfile() == null) { |
| 6822 | // assume no access if the card or profile is unavailable |
| 6823 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6824 | continue; |
| 6825 | } |
| 6826 | UiccProfile profile = card.getUiccProfile(); |
| 6827 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6828 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6829 | filteredInfos.add(cardInfo); |
| 6830 | } else { |
| 6831 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6832 | } |
| 6833 | } |
| 6834 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6835 | } finally { |
| 6836 | Binder.restoreCallingIdentity(identity); |
| 6837 | } |
| 6838 | } |
| 6839 | |
| 6840 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6841 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6842 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6843 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6844 | final long identity = Binder.clearCallingIdentity(); |
| 6845 | try { |
| 6846 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6847 | if (slots == null) { |
| 6848 | Rlog.i(LOG_TAG, "slots is null."); |
| 6849 | return null; |
| 6850 | } |
| 6851 | |
| 6852 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6853 | for (int i = 0; i < slots.length; i++) { |
| 6854 | UiccSlot slot = slots[i]; |
| 6855 | if (slot == null) { |
| 6856 | continue; |
| 6857 | } |
| 6858 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6859 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6860 | UiccCard card = slot.getUiccCard(); |
| 6861 | if (card != null) { |
| 6862 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6863 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6864 | cardId = slot.getEid(); |
| 6865 | if (TextUtils.isEmpty(cardId)) { |
| 6866 | cardId = slot.getIccId(); |
| 6867 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | } |
| 6869 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6870 | if (cardId != null) { |
| 6871 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6872 | // if cardId is an EID, it's all digits so this is fine |
| 6873 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6874 | } |
| 6875 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6876 | int cardState = 0; |
| 6877 | switch (slot.getCardState()) { |
| 6878 | case CARDSTATE_ABSENT: |
| 6879 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6880 | break; |
| 6881 | case CARDSTATE_PRESENT: |
| 6882 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6883 | break; |
| 6884 | case CARDSTATE_ERROR: |
| 6885 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6886 | break; |
| 6887 | case CARDSTATE_RESTRICTED: |
| 6888 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6889 | break; |
| 6890 | default: |
| 6891 | break; |
| 6892 | |
| 6893 | } |
| 6894 | |
| 6895 | infos[i] = new UiccSlotInfo( |
| 6896 | slot.isActive(), |
| 6897 | slot.isEuicc(), |
| 6898 | cardId, |
| 6899 | cardState, |
| 6900 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6901 | slot.isExtendedApduSupported(), |
| 6902 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6903 | } |
| 6904 | return infos; |
| 6905 | } finally { |
| 6906 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6907 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6908 | } |
| 6909 | |
| 6910 | @Override |
| 6911 | public boolean switchSlots(int[] physicalSlots) { |
| 6912 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6913 | |
| 6914 | final long identity = Binder.clearCallingIdentity(); |
| 6915 | try { |
| 6916 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6917 | } finally { |
| 6918 | Binder.restoreCallingIdentity(identity); |
| 6919 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6920 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6921 | |
| 6922 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6923 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6924 | final long identity = Binder.clearCallingIdentity(); |
| 6925 | try { |
| 6926 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6927 | } finally { |
| 6928 | Binder.restoreCallingIdentity(identity); |
| 6929 | } |
| 6930 | } |
| 6931 | |
| 6932 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6933 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6934 | enforceModifyPermission(); |
| 6935 | final Phone phone = getPhone(subId); |
| 6936 | if (phone == null) { |
| 6937 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6938 | return; |
| 6939 | } |
| 6940 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6941 | final long identity = Binder.clearCallingIdentity(); |
| 6942 | try { |
| 6943 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6944 | } finally { |
| 6945 | Binder.restoreCallingIdentity(identity); |
| 6946 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6947 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6948 | |
| 6949 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6950 | * A test API to reload the UICC profile. |
| 6951 | * |
| 6952 | * <p>Requires that the calling app has permission |
| 6953 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6954 | * @hide |
| 6955 | */ |
| 6956 | @Override |
| 6957 | public void refreshUiccProfile(int subId) { |
| 6958 | enforceModifyPermission(); |
| 6959 | |
| 6960 | final long identity = Binder.clearCallingIdentity(); |
| 6961 | try { |
| 6962 | Phone phone = getPhone(subId); |
| 6963 | if (phone == null) { |
| 6964 | return; |
| 6965 | } |
| 6966 | UiccCard uiccCard = phone.getUiccCard(); |
| 6967 | if (uiccCard == null) { |
| 6968 | return; |
| 6969 | } |
| 6970 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6971 | if (uiccProfile == null) { |
| 6972 | return; |
| 6973 | } |
| 6974 | uiccProfile.refresh(); |
| 6975 | } finally { |
| 6976 | Binder.restoreCallingIdentity(identity); |
| 6977 | } |
| 6978 | } |
| 6979 | |
| 6980 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6981 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6982 | */ |
| 6983 | private boolean getDefaultDataEnabled() { |
| 6984 | return "true".equalsIgnoreCase( |
| 6985 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6986 | } |
| 6987 | |
| 6988 | /** |
| 6989 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6990 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6991 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6992 | */ |
| 6993 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6994 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6995 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6996 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6997 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6998 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6999 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7000 | return isDataRoamingEnabled; |
| 7001 | } |
| 7002 | |
| 7003 | /** |
| 7004 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7005 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7006 | */ |
| 7007 | private int getDefaultNetworkType(int subId) { |
| 7008 | return Integer.parseInt( |
| 7009 | TelephonyManager.getTelephonyProperty( |
| 7010 | mSubscriptionController.getPhoneId(subId), |
| 7011 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 7012 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 7013 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7014 | |
| 7015 | @Override |
| 7016 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7017 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7018 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | final Phone phone = getPhone(subId); |
| 7023 | if (phone == null) { |
| 7024 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7025 | return; |
| 7026 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7027 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7028 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7029 | } finally { |
| 7030 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7031 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7032 | } |
| 7033 | |
| 7034 | @Override |
| 7035 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7036 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7037 | |
| 7038 | final long identity = Binder.clearCallingIdentity(); |
| 7039 | try { |
| 7040 | final Phone phone = getPhone(subId); |
| 7041 | if (phone == null) { |
| 7042 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7043 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7044 | } |
| 7045 | return phone.getCarrierIdListVersion(); |
| 7046 | } finally { |
| 7047 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7048 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7049 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7050 | |
| 7051 | @Override |
| 7052 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 7053 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7054 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 7055 | return -1; |
| 7056 | } |
| 7057 | |
| 7058 | final long identity = Binder.clearCallingIdentity(); |
| 7059 | try { |
| 7060 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7061 | } finally { |
| 7062 | Binder.restoreCallingIdentity(identity); |
| 7063 | } |
| 7064 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7065 | |
| 7066 | @Override |
| 7067 | public int getCdmaRoamingMode(int subId) { |
| 7068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7069 | mApp, subId, "getCdmaRoamingMode"); |
| 7070 | |
| 7071 | final long identity = Binder.clearCallingIdentity(); |
| 7072 | try { |
| 7073 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7074 | } finally { |
| 7075 | Binder.restoreCallingIdentity(identity); |
| 7076 | } |
| 7077 | } |
| 7078 | |
| 7079 | @Override |
| 7080 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7082 | mApp, subId, "setCdmaRoamingMode"); |
| 7083 | |
| 7084 | final long identity = Binder.clearCallingIdentity(); |
| 7085 | try { |
| 7086 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7087 | } finally { |
| 7088 | Binder.restoreCallingIdentity(identity); |
| 7089 | } |
| 7090 | } |
| 7091 | |
| 7092 | @Override |
| 7093 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7095 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7096 | |
| 7097 | final long identity = Binder.clearCallingIdentity(); |
| 7098 | try { |
| 7099 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7100 | } finally { |
| 7101 | Binder.restoreCallingIdentity(identity); |
| 7102 | } |
| 7103 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7104 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7105 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7106 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7107 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7108 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7109 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7110 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7111 | } |
| 7112 | final long identity = Binder.clearCallingIdentity(); |
| 7113 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7114 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7115 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7116 | if (phone.getEmergencyNumberTracker() != null |
| 7117 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7118 | emergencyNumberListInternal.put( |
| 7119 | phone.getSubId(), |
| 7120 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7121 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7122 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7123 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7124 | } finally { |
| 7125 | Binder.restoreCallingIdentity(identity); |
| 7126 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7127 | } |
| 7128 | |
| 7129 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7130 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7131 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7132 | if (!exactMatch) { |
| 7133 | TelephonyPermissions |
| 7134 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7135 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7136 | } |
| 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7139 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7140 | if (phone.getEmergencyNumberTracker() != null |
| 7141 | && phone.getEmergencyNumberTracker() != null) { |
| 7142 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7143 | number, exactMatch)) { |
| 7144 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7145 | } |
| 7146 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7147 | } |
| 7148 | return false; |
| 7149 | } finally { |
| 7150 | Binder.restoreCallingIdentity(identity); |
| 7151 | } |
| 7152 | } |
| 7153 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7154 | /** |
| 7155 | * Update emergency number list for test mode. |
| 7156 | */ |
| 7157 | @Override |
| 7158 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7159 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7160 | "updateEmergencyNumberListTestMode"); |
| 7161 | |
| 7162 | final long identity = Binder.clearCallingIdentity(); |
| 7163 | try { |
| 7164 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7165 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7166 | if (tracker != null) { |
| 7167 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7168 | } |
| 7169 | } |
| 7170 | } finally { |
| 7171 | Binder.restoreCallingIdentity(identity); |
| 7172 | } |
| 7173 | } |
| 7174 | |
| 7175 | /** |
| 7176 | * Get the full emergency number list for test mode. |
| 7177 | */ |
| 7178 | @Override |
| 7179 | public List<String> getEmergencyNumberListTestMode() { |
| 7180 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7181 | "getEmergencyNumberListTestMode"); |
| 7182 | |
| 7183 | final long identity = Binder.clearCallingIdentity(); |
| 7184 | try { |
| 7185 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7186 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7187 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7188 | if (tracker != null) { |
| 7189 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7190 | emergencyNumbers.add(num.getNumber()); |
| 7191 | } |
| 7192 | } |
| 7193 | } |
| 7194 | return new ArrayList<>(emergencyNumbers); |
| 7195 | } finally { |
| 7196 | Binder.restoreCallingIdentity(identity); |
| 7197 | } |
| 7198 | } |
| 7199 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7200 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7201 | public int getEmergencyNumberDbVersion(int subId) { |
| 7202 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7203 | |
| 7204 | final long identity = Binder.clearCallingIdentity(); |
| 7205 | try { |
| 7206 | final Phone phone = getPhone(subId); |
| 7207 | if (phone == null) { |
| 7208 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7209 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7210 | } |
| 7211 | return phone.getEmergencyNumberDbVersion(); |
| 7212 | } finally { |
| 7213 | Binder.restoreCallingIdentity(identity); |
| 7214 | } |
| 7215 | } |
| 7216 | |
| 7217 | @Override |
| 7218 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7219 | enforceModifyPermission(); |
| 7220 | |
| 7221 | final long identity = Binder.clearCallingIdentity(); |
| 7222 | try { |
| 7223 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7224 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7225 | if (tracker != null) { |
| 7226 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7227 | } |
| 7228 | } |
| 7229 | } finally { |
| 7230 | Binder.restoreCallingIdentity(identity); |
| 7231 | } |
| 7232 | } |
| 7233 | |
| 7234 | @Override |
| 7235 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7236 | enforceActiveEmergencySessionPermission(); |
| 7237 | |
| 7238 | final long identity = Binder.clearCallingIdentity(); |
| 7239 | try { |
| 7240 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7241 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7242 | if (tracker != null) { |
| 7243 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7244 | } |
| 7245 | } |
| 7246 | } finally { |
| 7247 | Binder.restoreCallingIdentity(identity); |
| 7248 | } |
| 7249 | } |
| 7250 | |
| 7251 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7252 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7253 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7254 | Phone phone = getPhone(subId); |
| 7255 | if (phone == null) { |
| 7256 | return null; |
| 7257 | } |
| 7258 | final long identity = Binder.clearCallingIdentity(); |
| 7259 | try { |
| 7260 | UiccProfile profile = UiccController.getInstance() |
| 7261 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7262 | if (profile != null) { |
| 7263 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7264 | } |
| 7265 | } finally { |
| 7266 | Binder.restoreCallingIdentity(identity); |
| 7267 | } |
| 7268 | return null; |
| 7269 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7270 | |
| 7271 | /** |
| 7272 | * Enable or disable a modem stack. |
| 7273 | */ |
| 7274 | @Override |
| 7275 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7276 | enforceModifyPermission(); |
| 7277 | |
| 7278 | final long identity = Binder.clearCallingIdentity(); |
| 7279 | try { |
| 7280 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7281 | if (phone == null) { |
| 7282 | return false; |
| 7283 | } else { |
| 7284 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7285 | } |
| 7286 | } finally { |
| 7287 | Binder.restoreCallingIdentity(identity); |
| 7288 | } |
| 7289 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7290 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7291 | /** |
| 7292 | * Whether a modem stack is enabled or not. |
| 7293 | */ |
| 7294 | @Override |
| 7295 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7296 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7297 | if (phone == null) return false; |
| 7298 | |
| 7299 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7300 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7301 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7302 | } |
| 7303 | |
| 7304 | final long identity = Binder.clearCallingIdentity(); |
| 7305 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7306 | try { |
| 7307 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7308 | } catch (NoSuchElementException ex) { |
| 7309 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7310 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7311 | } finally { |
| 7312 | Binder.restoreCallingIdentity(identity); |
| 7313 | } |
| 7314 | } |
| 7315 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7316 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7317 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7318 | enforceModifyPermission(); |
| 7319 | |
| 7320 | final long identity = Binder.clearCallingIdentity(); |
| 7321 | try { |
| 7322 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7323 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7324 | .commit(); |
| 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
| 7327 | } |
| 7328 | } |
| 7329 | |
| 7330 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7331 | @TelephonyManager.IsMultiSimSupportedResult |
| 7332 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7333 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7334 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7335 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7336 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7337 | |
| 7338 | final long identity = Binder.clearCallingIdentity(); |
| 7339 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7340 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7341 | } finally { |
| 7342 | Binder.restoreCallingIdentity(identity); |
| 7343 | } |
| 7344 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7345 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7346 | @TelephonyManager.IsMultiSimSupportedResult |
| 7347 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7348 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7349 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7350 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7351 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7352 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7353 | } |
| 7354 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7355 | // supported by the modem, indicate that it is restricted. |
| 7356 | PhoneCapability staticCapability = |
| 7357 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7358 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7359 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7360 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7361 | } |
| 7362 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7363 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7364 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7365 | } |
| 7366 | // Check if support of multiple SIMs is restricted by carrier |
| 7367 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7368 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7369 | } |
| 7370 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7371 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7372 | } |
| 7373 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7374 | /** |
| 7375 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7376 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7377 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7378 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7379 | * @param numOfSims number of active sims we want to switch to |
| 7380 | */ |
| 7381 | @Override |
| 7382 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7383 | if (numOfSims == 1) { |
| 7384 | enforceModifyPermission(); |
| 7385 | } else { |
| 7386 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7387 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7388 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7389 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7390 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7391 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7392 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7393 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7394 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7395 | return; |
| 7396 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7397 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7398 | } finally { |
| 7399 | Binder.restoreCallingIdentity(identity); |
| 7400 | } |
| 7401 | } |
| 7402 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7403 | @Override |
| 7404 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7405 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7406 | Phone phone = getPhone(subId); |
| 7407 | if (phone == null) { |
| 7408 | return false; |
| 7409 | } |
| 7410 | final long identity = Binder.clearCallingIdentity(); |
| 7411 | try { |
| 7412 | UiccCard uiccCard = phone.getUiccCard(); |
| 7413 | if (uiccCard == null) { |
| 7414 | return false; |
| 7415 | } |
| 7416 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7417 | if (uiccProfile == null) { |
| 7418 | return false; |
| 7419 | } |
| 7420 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7421 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7422 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7423 | } |
| 7424 | return false; |
| 7425 | } finally { |
| 7426 | Binder.restoreCallingIdentity(identity); |
| 7427 | } |
| 7428 | } |
| 7429 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7430 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7431 | * Get whether making changes to modem configurations will trigger reboot. |
| 7432 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7433 | */ |
| 7434 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7435 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7436 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7437 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7438 | return false; |
| 7439 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7440 | final long identity = Binder.clearCallingIdentity(); |
| 7441 | try { |
| 7442 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7443 | } finally { |
| 7444 | Binder.restoreCallingIdentity(identity); |
| 7445 | } |
| 7446 | } |
| 7447 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7448 | private void updateModemStateMetrics() { |
| 7449 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7450 | // TODO: check the state for each modem if the api is ready. |
| 7451 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7452 | } |
| 7453 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7454 | @Override |
| 7455 | public int[] getSlotsMapping() { |
| 7456 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7457 | |
| 7458 | final long identity = Binder.clearCallingIdentity(); |
| 7459 | try { |
| 7460 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7461 | // All logical slots should have a mapping to a physical slot. |
| 7462 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7463 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7464 | for (int i = 0; i < slotInfos.length; i++) { |
| 7465 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7466 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7467 | } |
| 7468 | } |
| 7469 | return logicalSlotsMapping; |
| 7470 | } finally { |
| 7471 | Binder.restoreCallingIdentity(identity); |
| 7472 | } |
| 7473 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7474 | |
| 7475 | /** |
| 7476 | * Get the IRadio HAL Version |
| 7477 | */ |
| 7478 | @Override |
| 7479 | public int getRadioHalVersion() { |
| 7480 | Phone phone = getDefaultPhone(); |
| 7481 | if (phone == null) return -1; |
| 7482 | HalVersion hv = phone.getHalVersion(); |
| 7483 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7484 | return hv.major * 100 + hv.minor; |
| 7485 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7486 | |
| 7487 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7488 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7489 | * corresponding network requests on a subId. |
| 7490 | * |
| 7491 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7492 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7493 | * 2) APN is un-metered for this subscription, or |
| 7494 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7495 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7496 | * |
| 7497 | * @return whether data is allowed for a apn type. |
| 7498 | * |
| 7499 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7500 | */ |
| 7501 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7502 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7503 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7504 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7505 | |
| 7506 | // Now that all security checks passes, perform the operation as ourselves. |
| 7507 | final long identity = Binder.clearCallingIdentity(); |
| 7508 | try { |
| 7509 | Phone phone = getPhone(subId); |
| 7510 | if (phone == null) return false; |
| 7511 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7512 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7513 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7514 | } finally { |
| 7515 | Binder.restoreCallingIdentity(identity); |
| 7516 | } |
| 7517 | } |
| 7518 | |
| 7519 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7520 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7521 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7522 | |
| 7523 | // Now that all security checks passes, perform the operation as ourselves. |
| 7524 | final long identity = Binder.clearCallingIdentity(); |
| 7525 | try { |
| 7526 | Phone phone = getPhone(subId); |
| 7527 | if (phone == null) return true; // By default return true. |
| 7528 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7529 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7530 | } finally { |
| 7531 | Binder.restoreCallingIdentity(identity); |
| 7532 | } |
| 7533 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7534 | |
| 7535 | @Override |
| 7536 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7537 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7538 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7539 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7540 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7541 | } |
| 7542 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7543 | Intent intent = new Intent(); |
| 7544 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7545 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7546 | // Bring up choose default SMS subscription dialog right now |
| 7547 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7548 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7549 | mApp.startActivity(intent); |
| 7550 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7551 | |
| 7552 | @Override |
| 7553 | public String getMmsUAProfUrl(int subId) { |
| 7554 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7555 | final long identity = Binder.clearCallingIdentity(); |
| 7556 | try { |
| 7557 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7558 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7559 | } finally { |
| 7560 | Binder.restoreCallingIdentity(identity); |
| 7561 | } |
| 7562 | } |
| 7563 | |
| 7564 | @Override |
| 7565 | public String getMmsUserAgent(int subId) { |
| 7566 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7567 | final long identity = Binder.clearCallingIdentity(); |
| 7568 | try { |
| 7569 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7570 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7571 | } finally { |
| 7572 | Binder.restoreCallingIdentity(identity); |
| 7573 | } |
| 7574 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7575 | |
| 7576 | @Override |
| 7577 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7578 | enforceModifyPermission(); |
| 7579 | |
| 7580 | // Now that all security checks passes, perform the operation as ourselves. |
| 7581 | final long identity = Binder.clearCallingIdentity(); |
| 7582 | try { |
| 7583 | Phone phone = getPhone(subId); |
| 7584 | if (phone == null) return false; |
| 7585 | |
| 7586 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7587 | } finally { |
| 7588 | Binder.restoreCallingIdentity(identity); |
| 7589 | } |
| 7590 | } |
| 7591 | |
| 7592 | @Override |
| 7593 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7594 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7595 | |
| 7596 | // Now that all security checks passes, perform the operation as ourselves. |
| 7597 | final long identity = Binder.clearCallingIdentity(); |
| 7598 | try { |
| 7599 | Phone phone = getPhone(subId); |
| 7600 | if (phone == null) return false; |
| 7601 | |
| 7602 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7603 | } finally { |
| 7604 | Binder.restoreCallingIdentity(identity); |
| 7605 | } |
| 7606 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7607 | |
| 7608 | /** |
| 7609 | * Updates whether conference event pacakge handling is enabled. |
| 7610 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7611 | * otherwise. |
| 7612 | */ |
| 7613 | @Override |
| 7614 | public void setCepEnabled(boolean isCepEnabled) { |
| 7615 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7616 | |
| 7617 | final long identity = Binder.clearCallingIdentity(); |
| 7618 | try { |
| 7619 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7620 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7621 | Phone defaultPhone = phone.getImsPhone(); |
| 7622 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7623 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7624 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7625 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7626 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7627 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7628 | + imsPhone.getMsisdn()); |
| 7629 | } |
| 7630 | } |
| 7631 | } finally { |
| 7632 | Binder.restoreCallingIdentity(identity); |
| 7633 | } |
| 7634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7635 | } |