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 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 22 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 23 | import android.Manifest.permission; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 24 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 26 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 27 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 28 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 31 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 32 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 33 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 34 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 36 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 47 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 48 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 49 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 50 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 52 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 53 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 54 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 61 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 63 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 64 | import android.telephony.Annotation.ApnType; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 65 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 66 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame^] | 67 | import android.telephony.CellIdentity; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 69 | import android.telephony.CellInfoGsm; |
| 70 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 71 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 72 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 73 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 74 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 75 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 76 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 77 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 78 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 79 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 80 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 81 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 82 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 83 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 84 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 85 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 86 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 87 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 88 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 89 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 91 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 92 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 93 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 94 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 95 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 96 | import android.telephony.data.ApnSetting; |
| 97 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 98 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 99 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 100 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 101 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 102 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 105 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 106 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 108 | import android.telephony.ims.feature.MmTelFeature; |
| 109 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 110 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 111 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 112 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 113 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 114 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 115 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 116 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 117 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 118 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 122 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 132 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.SmsApplication; |
| 145 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.IccIoResult; |
| 157 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 165 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 166 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 167 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 168 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 169 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 170 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 171 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 172 | import java.io.FileDescriptor; |
| 173 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 175 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 176 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 177 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 178 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 179 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 180 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 181 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 182 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 183 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * Implementation of the ITelephony interface. |
| 187 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 188 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 190 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 191 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 192 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 193 | |
| 194 | // Message codes used with mMainThreadHandler |
| 195 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 196 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 197 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 198 | private static final int CMD_OPEN_CHANNEL = 9; |
| 199 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 200 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 201 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 202 | private static final int CMD_NV_READ_ITEM = 13; |
| 203 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 204 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 205 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 206 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 207 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 208 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 209 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 210 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 211 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 212 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 213 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 214 | private static final int CMD_SEND_ENVELOPE = 25; |
| 215 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 216 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 217 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 218 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 219 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 220 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 221 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 222 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 223 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 224 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 225 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 226 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 227 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 228 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 229 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 230 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 231 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 232 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 233 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 234 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 235 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 236 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 237 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 238 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 239 | private static final int CMD_SWITCH_SLOTS = 50; |
| 240 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 241 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 242 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 243 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 244 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 245 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 246 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 247 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 248 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 249 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 250 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 251 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 252 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 253 | private static final int CMD_MODEM_REBOOT = 64; |
| 254 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 255 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 256 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 257 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 258 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 259 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 260 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame^] | 261 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 262 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 263 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 264 | // Parameters of select command. |
| 265 | private static final int SELECT_COMMAND = 0xA4; |
| 266 | private static final int SELECT_P1 = 0x04; |
| 267 | private static final int SELECT_P2 = 0; |
| 268 | private static final int SELECT_P3 = 0x10; |
| 269 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 270 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 271 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 272 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 273 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | /** The singleton instance. */ |
| 275 | private static PhoneInterfaceManager sInstance; |
| 276 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 277 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 278 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 279 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 280 | private AppOpsManager mAppOps; |
| 281 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 282 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 283 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 284 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 285 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 286 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 287 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 288 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 289 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 290 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 291 | // String to store multi SIM allowed |
| 292 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 293 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 294 | // The AID of ISD-R. |
| 295 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 296 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 297 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 298 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 299 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 300 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 301 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 302 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 303 | * A request object to use for transmitting data to an ICC. |
| 304 | */ |
| 305 | private static final class IccAPDUArgument { |
| 306 | public int channel, cla, command, p1, p2, p3; |
| 307 | public String data; |
| 308 | |
| 309 | public IccAPDUArgument(int channel, int cla, int command, |
| 310 | int p1, int p2, int p3, String data) { |
| 311 | this.channel = channel; |
| 312 | this.cla = cla; |
| 313 | this.command = command; |
| 314 | this.p1 = p1; |
| 315 | this.p2 = p2; |
| 316 | this.p3 = p3; |
| 317 | this.data = data; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 322 | * A request object to use for transmitting data to an ICC. |
| 323 | */ |
| 324 | private static final class ManualNetworkSelectionArgument { |
| 325 | public OperatorInfo operatorInfo; |
| 326 | public boolean persistSelection; |
| 327 | |
| 328 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 329 | this.operatorInfo = operatorInfo; |
| 330 | this.persistSelection = persistSelection; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 335 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 336 | * request after sending. The main thread will notify the request when it is complete. |
| 337 | */ |
| 338 | private static final class MainThreadRequest { |
| 339 | /** The argument to use for the request */ |
| 340 | public Object argument; |
| 341 | /** The result of the request that is run on the main thread */ |
| 342 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 343 | // The subscriber id that this request applies to. Defaults to |
| 344 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 345 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 346 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 347 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 348 | public Phone phone; |
| 349 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 350 | public WorkSource workSource; |
| 351 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 352 | public MainThreadRequest(Object argument) { |
| 353 | this.argument = argument; |
| 354 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 355 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 356 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 357 | this.argument = argument; |
| 358 | if (phone != null) { |
| 359 | this.phone = phone; |
| 360 | } |
| 361 | this.workSource = workSource; |
| 362 | } |
| 363 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 364 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 365 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 366 | if (subId != null) { |
| 367 | this.subId = subId; |
| 368 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 369 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 373 | private static final class IncomingThirdPartyCallArgs { |
| 374 | public final ComponentName component; |
| 375 | public final String callId; |
| 376 | public final String callerDisplayName; |
| 377 | |
| 378 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 379 | String callerDisplayName) { |
| 380 | this.component = component; |
| 381 | this.callId = callId; |
| 382 | this.callerDisplayName = callerDisplayName; |
| 383 | } |
| 384 | } |
| 385 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 386 | /** |
| 387 | * A handler that processes messages on the main thread in the phone process. Since many |
| 388 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 389 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 390 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 391 | * on, which will be notified when the operation completes and will contain the result of the |
| 392 | * request. |
| 393 | * |
| 394 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 395 | * note that request.result must be set to something non-null for the calling thread to |
| 396 | * unblock. |
| 397 | */ |
| 398 | private final class MainThreadHandler extends Handler { |
| 399 | @Override |
| 400 | public void handleMessage(Message msg) { |
| 401 | MainThreadRequest request; |
| 402 | Message onCompleted; |
| 403 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 404 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 405 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 406 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 407 | |
| 408 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 409 | case CMD_HANDLE_USSD_REQUEST: { |
| 410 | request = (MainThreadRequest) msg.obj; |
| 411 | final Phone phone = getPhoneFromRequest(request); |
| 412 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 413 | String ussdRequest = ussdObject.first; |
| 414 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 415 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 416 | if (!isUssdApiAllowed(request.subId)) { |
| 417 | // Carrier does not support use of this API, return failure. |
| 418 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 419 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 420 | Bundle returnData = new Bundle(); |
| 421 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 422 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 423 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 424 | request.result = true; |
| 425 | notifyRequester(request); |
| 426 | return; |
| 427 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 428 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 429 | try { |
| 430 | request.result = phone != null |
| 431 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 432 | } catch (CallStateException cse) { |
| 433 | request.result = false; |
| 434 | } |
| 435 | // Wake up the requesting thread |
| 436 | notifyRequester(request); |
| 437 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 440 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 441 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 442 | final Phone phone = getPhoneFromRequest(request); |
| 443 | request.result = phone != null ? |
| 444 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 445 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 447 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 448 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 449 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 452 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 453 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 454 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 455 | if (uiccCard == null) { |
| 456 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 457 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 458 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 459 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 460 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 461 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 462 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 464 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 465 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 466 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 467 | break; |
| 468 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 469 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 470 | ar = (AsyncResult) msg.obj; |
| 471 | request = (MainThreadRequest) ar.userObj; |
| 472 | if (ar.exception == null && ar.result != null) { |
| 473 | request.result = ar.result; |
| 474 | } else { |
| 475 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 476 | if (ar.result == null) { |
| 477 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 478 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 479 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 480 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 481 | } else { |
| 482 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 483 | } |
| 484 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 485 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 486 | break; |
| 487 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 488 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 489 | request = (MainThreadRequest) msg.obj; |
| 490 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 491 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 492 | if (uiccCard == null) { |
| 493 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 494 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 496 | } else { |
| 497 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 498 | request); |
| 499 | uiccCard.iccTransmitApduBasicChannel( |
| 500 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 501 | iccArgument.p3, iccArgument.data, onCompleted); |
| 502 | } |
| 503 | break; |
| 504 | |
| 505 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 506 | ar = (AsyncResult) msg.obj; |
| 507 | request = (MainThreadRequest) ar.userObj; |
| 508 | if (ar.exception == null && ar.result != null) { |
| 509 | request.result = ar.result; |
| 510 | } else { |
| 511 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 512 | if (ar.result == null) { |
| 513 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 514 | } else if (ar.exception instanceof CommandException) { |
| 515 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 516 | ar.exception); |
| 517 | } else { |
| 518 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 519 | } |
| 520 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | break; |
| 523 | |
| 524 | case CMD_EXCHANGE_SIM_IO: |
| 525 | request = (MainThreadRequest) msg.obj; |
| 526 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 527 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | if (uiccCard == null) { |
| 529 | loge("iccExchangeSimIO: No UICC"); |
| 530 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | } else { |
| 533 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 534 | request); |
| 535 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 536 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 537 | iccArgument.data, onCompleted); |
| 538 | } |
| 539 | break; |
| 540 | |
| 541 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 542 | ar = (AsyncResult) msg.obj; |
| 543 | request = (MainThreadRequest) ar.userObj; |
| 544 | if (ar.exception == null && ar.result != null) { |
| 545 | request.result = ar.result; |
| 546 | } else { |
| 547 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 548 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 550 | break; |
| 551 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 552 | case CMD_SEND_ENVELOPE: |
| 553 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 554 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 555 | if (uiccCard == null) { |
| 556 | loge("sendEnvelopeWithStatus: No UICC"); |
| 557 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 558 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 559 | } else { |
| 560 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 561 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 562 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 563 | break; |
| 564 | |
| 565 | case EVENT_SEND_ENVELOPE_DONE: |
| 566 | ar = (AsyncResult) msg.obj; |
| 567 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 568 | if (ar.exception == null && ar.result != null) { |
| 569 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 570 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 571 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 572 | if (ar.result == null) { |
| 573 | loge("sendEnvelopeWithStatus: Empty response"); |
| 574 | } else if (ar.exception instanceof CommandException) { |
| 575 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 576 | ar.exception); |
| 577 | } else { |
| 578 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 579 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 580 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 581 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 582 | break; |
| 583 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 584 | case CMD_OPEN_CHANNEL: |
| 585 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 586 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 587 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 588 | if (uiccCard == null) { |
| 589 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 590 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 591 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | } else { |
| 594 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 595 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 596 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 597 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 598 | break; |
| 599 | |
| 600 | case EVENT_OPEN_CHANNEL_DONE: |
| 601 | ar = (AsyncResult) msg.obj; |
| 602 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 605 | int[] result = (int[]) ar.result; |
| 606 | int channelId = result[0]; |
| 607 | byte[] selectResponse = null; |
| 608 | if (result.length > 1) { |
| 609 | selectResponse = new byte[result.length - 1]; |
| 610 | for (int i = 1; i < result.length; ++i) { |
| 611 | selectResponse[i - 1] = (byte) result[i]; |
| 612 | } |
| 613 | } |
| 614 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 615 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | if (ar.result == null) { |
| 618 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | if (ar.exception != null) { |
| 621 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 622 | } |
| 623 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 624 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 625 | if (ar.exception instanceof CommandException) { |
| 626 | CommandException.Error error = |
| 627 | ((CommandException) (ar.exception)).getCommandError(); |
| 628 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 629 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 630 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 631 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 635 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 637 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 638 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 639 | break; |
| 640 | |
| 641 | case CMD_CLOSE_CHANNEL: |
| 642 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 643 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 644 | if (uiccCard == null) { |
| 645 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 646 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 647 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 648 | } else { |
| 649 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 650 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 651 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | break; |
| 653 | |
| 654 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 655 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 656 | break; |
| 657 | |
| 658 | case CMD_NV_READ_ITEM: |
| 659 | request = (MainThreadRequest) msg.obj; |
| 660 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 661 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 662 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | ar = (AsyncResult) msg.obj; |
| 667 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | if (ar.exception == null && ar.result != null) { |
| 669 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 671 | request.result = ""; |
| 672 | if (ar.result == null) { |
| 673 | loge("nvReadItem: Empty response"); |
| 674 | } else if (ar.exception instanceof CommandException) { |
| 675 | loge("nvReadItem: CommandException: " + |
| 676 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | } |
| 680 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 681 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | break; |
| 683 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | case CMD_NV_WRITE_ITEM: |
| 685 | request = (MainThreadRequest) msg.obj; |
| 686 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 687 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 688 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 689 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | break; |
| 691 | |
| 692 | case EVENT_NV_WRITE_ITEM_DONE: |
| 693 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 694 | break; |
| 695 | |
| 696 | case CMD_NV_WRITE_CDMA_PRL: |
| 697 | request = (MainThreadRequest) msg.obj; |
| 698 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 699 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | break; |
| 701 | |
| 702 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 703 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 704 | break; |
| 705 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 706 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 707 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 708 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 709 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 710 | break; |
| 711 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 712 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 713 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 716 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 717 | request = (MainThreadRequest) msg.obj; |
| 718 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 719 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 723 | ar = (AsyncResult) msg.obj; |
| 724 | request = (MainThreadRequest) ar.userObj; |
| 725 | if (ar.exception == null && ar.result != null) { |
| 726 | request.result = ar.result; // Integer |
| 727 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 728 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 729 | if (ar.result == null) { |
| 730 | loge("getPreferredNetworkType: Empty response"); |
| 731 | } else if (ar.exception instanceof CommandException) { |
| 732 | loge("getPreferredNetworkType: CommandException: " + |
| 733 | ar.exception); |
| 734 | } else { |
| 735 | loge("getPreferredNetworkType: Unknown exception"); |
| 736 | } |
| 737 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 738 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 739 | break; |
| 740 | |
| 741 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 742 | request = (MainThreadRequest) msg.obj; |
| 743 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 744 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 745 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
| 748 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 749 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 750 | break; |
| 751 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 752 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 753 | request = (MainThreadRequest)msg.obj; |
| 754 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 755 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 759 | ar = (AsyncResult)msg.obj; |
| 760 | request = (MainThreadRequest)ar.userObj; |
| 761 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 763 | break; |
| 764 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 765 | case CMD_SET_VOICEMAIL_NUMBER: |
| 766 | request = (MainThreadRequest) msg.obj; |
| 767 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 768 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 769 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 770 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 774 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 775 | break; |
| 776 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 777 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 778 | request = (MainThreadRequest) msg.obj; |
| 779 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 780 | request); |
| 781 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 782 | break; |
| 783 | |
| 784 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 785 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 786 | break; |
| 787 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 788 | case CMD_PERFORM_NETWORK_SCAN: |
| 789 | request = (MainThreadRequest) msg.obj; |
| 790 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 791 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 792 | break; |
| 793 | |
| 794 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 795 | ar = (AsyncResult) msg.obj; |
| 796 | request = (MainThreadRequest) ar.userObj; |
| 797 | CellNetworkScanResult cellScanResult; |
| 798 | if (ar.exception == null && ar.result != null) { |
| 799 | cellScanResult = new CellNetworkScanResult( |
| 800 | CellNetworkScanResult.STATUS_SUCCESS, |
| 801 | (List<OperatorInfo>) ar.result); |
| 802 | } else { |
| 803 | if (ar.result == null) { |
| 804 | loge("getCellNetworkScanResults: Empty response"); |
| 805 | } |
| 806 | if (ar.exception != null) { |
| 807 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 808 | } |
| 809 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 810 | if (ar.exception instanceof CommandException) { |
| 811 | CommandException.Error error = |
| 812 | ((CommandException) (ar.exception)).getCommandError(); |
| 813 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 814 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 815 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 816 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 817 | } |
| 818 | } |
| 819 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 820 | } |
| 821 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 822 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 823 | break; |
| 824 | |
| 825 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 826 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 827 | ManualNetworkSelectionArgument selArg = |
| 828 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 829 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 830 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 831 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 832 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 836 | ar = (AsyncResult) msg.obj; |
| 837 | request = (MainThreadRequest) ar.userObj; |
| 838 | if (ar.exception == null) { |
| 839 | request.result = true; |
| 840 | } else { |
| 841 | request.result = false; |
| 842 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 843 | } |
| 844 | notifyRequester(request); |
| 845 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 846 | break; |
| 847 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 848 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 849 | request = (MainThreadRequest) msg.obj; |
| 850 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 851 | if (defaultPhone != null) { |
| 852 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 853 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 854 | break; |
| 855 | |
| 856 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 857 | ar = (AsyncResult) msg.obj; |
| 858 | request = (MainThreadRequest) ar.userObj; |
| 859 | if (ar.exception == null && ar.result != null) { |
| 860 | request.result = ar.result; |
| 861 | } else { |
| 862 | if (ar.result == null) { |
| 863 | loge("queryModemActivityInfo: Empty response"); |
| 864 | } else if (ar.exception instanceof CommandException) { |
| 865 | loge("queryModemActivityInfo: CommandException: " + |
| 866 | ar.exception); |
| 867 | } else { |
| 868 | loge("queryModemActivityInfo: Unknown exception"); |
| 869 | } |
| 870 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 871 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 872 | if (request.result == null) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 873 | request.result = new ModemActivityInfo(0, 0, 0, null, 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 874 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 875 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 876 | break; |
| 877 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 878 | case CMD_SET_ALLOWED_CARRIERS: |
| 879 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 880 | CarrierRestrictionRules argument = |
| 881 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 882 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 883 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 884 | break; |
| 885 | |
| 886 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 887 | ar = (AsyncResult) msg.obj; |
| 888 | request = (MainThreadRequest) ar.userObj; |
| 889 | if (ar.exception == null && ar.result != null) { |
| 890 | request.result = ar.result; |
| 891 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 892 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 893 | if (ar.exception instanceof CommandException) { |
| 894 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 895 | CommandException.Error error = |
| 896 | ((CommandException) (ar.exception)).getCommandError(); |
| 897 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 898 | request.result = |
| 899 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 900 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 901 | } else { |
| 902 | loge("setAllowedCarriers: Unknown exception"); |
| 903 | } |
| 904 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 905 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 906 | break; |
| 907 | |
| 908 | case CMD_GET_ALLOWED_CARRIERS: |
| 909 | request = (MainThreadRequest) msg.obj; |
| 910 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 911 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 915 | ar = (AsyncResult) msg.obj; |
| 916 | request = (MainThreadRequest) ar.userObj; |
| 917 | if (ar.exception == null && ar.result != null) { |
| 918 | request.result = ar.result; |
| 919 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 920 | request.result = new IllegalStateException( |
| 921 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 922 | if (ar.result == null) { |
| 923 | loge("getAllowedCarriers: Empty response"); |
| 924 | } else if (ar.exception instanceof CommandException) { |
| 925 | loge("getAllowedCarriers: CommandException: " + |
| 926 | ar.exception); |
| 927 | } else { |
| 928 | loge("getAllowedCarriers: Unknown exception"); |
| 929 | } |
| 930 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 931 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 932 | break; |
| 933 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 934 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 935 | ar = (AsyncResult) msg.obj; |
| 936 | request = (MainThreadRequest) ar.userObj; |
| 937 | if (ar.exception == null && ar.result != null) { |
| 938 | request.result = ar.result; |
| 939 | } else { |
| 940 | request.result = new IllegalArgumentException( |
| 941 | "Failed to retrieve Forbidden Plmns"); |
| 942 | if (ar.result == null) { |
| 943 | loge("getForbiddenPlmns: Empty response"); |
| 944 | } else { |
| 945 | loge("getForbiddenPlmns: Unknown exception"); |
| 946 | } |
| 947 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 948 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 949 | break; |
| 950 | |
| 951 | case CMD_GET_FORBIDDEN_PLMNS: |
| 952 | request = (MainThreadRequest) msg.obj; |
| 953 | uiccCard = getUiccCardFromRequest(request); |
| 954 | if (uiccCard == null) { |
| 955 | loge("getForbiddenPlmns() UiccCard is null"); |
| 956 | request.result = new IllegalArgumentException( |
| 957 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 958 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 959 | break; |
| 960 | } |
| 961 | Integer appType = (Integer) request.argument; |
| 962 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 963 | if (uiccApp == null) { |
| 964 | loge("getForbiddenPlmns() no app with specified type -- " |
| 965 | + appType); |
| 966 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 967 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 968 | break; |
| 969 | } else { |
| 970 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 971 | + " specified type -- " + appType); |
| 972 | } |
| 973 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 974 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 975 | onCompleted); |
| 976 | break; |
| 977 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 978 | case CMD_SWITCH_SLOTS: |
| 979 | request = (MainThreadRequest) msg.obj; |
| 980 | int[] physicalSlots = (int[]) request.argument; |
| 981 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 982 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 983 | break; |
| 984 | |
| 985 | case EVENT_SWITCH_SLOTS_DONE: |
| 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
| 988 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 989 | notifyRequester(request); |
| 990 | break; |
| 991 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 992 | request = (MainThreadRequest) msg.obj; |
| 993 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 994 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 995 | break; |
| 996 | |
| 997 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 998 | ar = (AsyncResult) msg.obj; |
| 999 | request = (MainThreadRequest) ar.userObj; |
| 1000 | if (ar.exception != null) { |
| 1001 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1002 | } else { |
| 1003 | int mode = ((int[]) ar.result)[0]; |
| 1004 | if (mode == 0) { |
| 1005 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1006 | } else { |
| 1007 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1008 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1009 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1010 | notifyRequester(request); |
| 1011 | break; |
| 1012 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1013 | request = (MainThreadRequest) msg.obj; |
| 1014 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1015 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1016 | break; |
| 1017 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1018 | ar = (AsyncResult) msg.obj; |
| 1019 | request = (MainThreadRequest) ar.userObj; |
| 1020 | if (ar.exception != null) { |
| 1021 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1022 | } else { |
| 1023 | request.result = ((int[]) ar.result)[0]; |
| 1024 | } |
| 1025 | notifyRequester(request); |
| 1026 | break; |
| 1027 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1030 | int mode = (int) request.argument; |
| 1031 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1032 | break; |
| 1033 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1034 | ar = (AsyncResult) msg.obj; |
| 1035 | request = (MainThreadRequest) ar.userObj; |
| 1036 | request.result = ar.exception == null; |
| 1037 | notifyRequester(request); |
| 1038 | break; |
| 1039 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1040 | request = (MainThreadRequest) msg.obj; |
| 1041 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1042 | int subscriptionMode = (int) request.argument; |
| 1043 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1044 | break; |
| 1045 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1046 | ar = (AsyncResult) msg.obj; |
| 1047 | request = (MainThreadRequest) ar.userObj; |
| 1048 | request.result = ar.exception == null; |
| 1049 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1050 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1051 | case CMD_GET_ALL_CELL_INFO: |
| 1052 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1053 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1054 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1055 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1056 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1057 | ar = (AsyncResult) msg.obj; |
| 1058 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1059 | // If a timeout occurs, the response will be null |
| 1060 | request.result = (ar.exception == null && ar.result != null) |
| 1061 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1062 | synchronized (request) { |
| 1063 | request.notifyAll(); |
| 1064 | } |
| 1065 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1066 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1067 | request = (MainThreadRequest) msg.obj; |
| 1068 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1069 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1070 | break; |
| 1071 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1072 | ar = (AsyncResult) msg.obj; |
| 1073 | request = (MainThreadRequest) ar.userObj; |
| 1074 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1075 | try { |
| 1076 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1077 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1078 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1079 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1080 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1081 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1082 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1083 | } else { |
| 1084 | // use the result as returned |
| 1085 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1086 | } |
| 1087 | } catch (RemoteException re) { |
| 1088 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1089 | } |
| 1090 | break; |
| 1091 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1092 | request = (MainThreadRequest) msg.obj; |
| 1093 | WorkSource ws = (WorkSource) request.argument; |
| 1094 | Phone phone = getPhoneFromRequest(request); |
| 1095 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1096 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1097 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1098 | ar = (AsyncResult) msg.obj; |
| 1099 | request = (MainThreadRequest) ar.userObj; |
| 1100 | if (ar.exception == null) { |
| 1101 | request.result = ar.result; |
| 1102 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1103 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1104 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1105 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1106 | } |
| 1107 | |
| 1108 | synchronized (request) { |
| 1109 | request.notifyAll(); |
| 1110 | } |
| 1111 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1112 | case CMD_MODEM_REBOOT: |
| 1113 | request = (MainThreadRequest) msg.obj; |
| 1114 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1115 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1116 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1117 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1118 | handleNullReturnEvent(msg, "rebootModem"); |
| 1119 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1120 | case CMD_REQUEST_ENABLE_MODEM: |
| 1121 | request = (MainThreadRequest) msg.obj; |
| 1122 | boolean enable = (boolean) request.argument; |
| 1123 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1124 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1125 | PhoneConfigurationManager.getInstance() |
| 1126 | .enablePhone(request.phone, enable, onCompleted); |
| 1127 | break; |
| 1128 | case EVENT_ENABLE_MODEM_DONE: |
| 1129 | ar = (AsyncResult) msg.obj; |
| 1130 | request = (MainThreadRequest) ar.userObj; |
| 1131 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1132 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1133 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1134 | if ((boolean) request.result) { |
| 1135 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1136 | updateModemStateMetrics(); |
| 1137 | } else { |
| 1138 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1139 | + ar.exception); |
| 1140 | } |
| 1141 | notifyRequester(request); |
| 1142 | break; |
| 1143 | case CMD_GET_MODEM_STATUS: |
| 1144 | request = (MainThreadRequest) msg.obj; |
| 1145 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1146 | PhoneConfigurationManager.getInstance() |
| 1147 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1148 | break; |
| 1149 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1150 | ar = (AsyncResult) msg.obj; |
| 1151 | request = (MainThreadRequest) ar.userObj; |
| 1152 | int id = request.phone.getPhoneId(); |
| 1153 | if (ar.exception == null && ar.result != null) { |
| 1154 | request.result = ar.result; |
| 1155 | //update the cache as modem status has changed |
| 1156 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1157 | (boolean) request.result); |
| 1158 | } else { |
| 1159 | // Return true if modem status cannot be retrieved. For most cases, |
| 1160 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1161 | // and disable modem are not supported. Modem is always on. |
| 1162 | // TODO: this should be fixed in R to support a third |
| 1163 | // status UNKNOWN b/131631629 |
| 1164 | request.result = true; |
| 1165 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1166 | + ar.exception); |
| 1167 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1168 | notifyRequester(request); |
| 1169 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame^] | 1170 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1171 | ar = (AsyncResult) msg.obj; |
| 1172 | request = (MainThreadRequest) ar.userObj; |
| 1173 | if (ar.exception == null && ar.result != null) { |
| 1174 | request.result = ar.result; |
| 1175 | } else { |
| 1176 | request.result = -1; |
| 1177 | loge("Failed to set Forbidden Plmns"); |
| 1178 | if (ar.result == null) { |
| 1179 | loge("setForbidenPlmns: Empty response"); |
| 1180 | } else if (ar.exception != null) { |
| 1181 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1182 | request.result = -1; |
| 1183 | } else { |
| 1184 | loge("setForbiddenPlmns: Unknown exception"); |
| 1185 | } |
| 1186 | } |
| 1187 | notifyRequester(request); |
| 1188 | break; |
| 1189 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1190 | request = (MainThreadRequest) msg.obj; |
| 1191 | uiccCard = getUiccCardFromRequest(request); |
| 1192 | if (uiccCard == null) { |
| 1193 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1194 | request.result = -1; |
| 1195 | notifyRequester(request); |
| 1196 | break; |
| 1197 | } |
| 1198 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1199 | (Pair<Integer, List<String>>) request.argument; |
| 1200 | appType = setFplmnsArgs.first; |
| 1201 | List<String> fplmns = setFplmnsArgs.second; |
| 1202 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1203 | if (uiccApp == null) { |
| 1204 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1205 | request.result = -1; |
| 1206 | loge("Failed to get UICC App"); |
| 1207 | notifyRequester(request); |
| 1208 | } else { |
| 1209 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1210 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1211 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1212 | } |
| 1213 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1214 | default: |
| 1215 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1216 | break; |
| 1217 | } |
| 1218 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1219 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1220 | private void notifyRequester(MainThreadRequest request) { |
| 1221 | synchronized (request) { |
| 1222 | request.notifyAll(); |
| 1223 | } |
| 1224 | } |
| 1225 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1226 | private void handleNullReturnEvent(Message msg, String command) { |
| 1227 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1228 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1229 | if (ar.exception == null) { |
| 1230 | request.result = true; |
| 1231 | } else { |
| 1232 | request.result = false; |
| 1233 | if (ar.exception instanceof CommandException) { |
| 1234 | loge(command + ": CommandException: " + ar.exception); |
| 1235 | } else { |
| 1236 | loge(command + ": Unknown exception"); |
| 1237 | } |
| 1238 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1239 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1240 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * Posts the specified command to be executed on the main thread, |
| 1245 | * waits for the request to complete, and returns the result. |
| 1246 | * @see #sendRequestAsync |
| 1247 | */ |
| 1248 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1249 | return sendRequest( |
| 1250 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * Posts the specified command to be executed on the main thread, |
| 1255 | * waits for the request to complete, and returns the result. |
| 1256 | * @see #sendRequestAsync |
| 1257 | */ |
| 1258 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1259 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1260 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -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 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1268 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1269 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | /** |
| 1273 | * Posts the specified command to be executed on the main thread, |
| 1274 | * waits for the request to complete, and returns the result. |
| 1275 | * @see #sendRequestAsync |
| 1276 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1277 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1278 | return sendRequest(command, argument, subId, null, workSource); |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * Posts the specified command to be executed on the main thread, |
| 1283 | * waits for the request to complete, and returns the result. |
| 1284 | * @see #sendRequestAsync |
| 1285 | */ |
| 1286 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1287 | return sendRequest( |
| 1288 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1289 | } |
| 1290 | |
| 1291 | /** |
| 1292 | * Posts the specified command to be executed on the main thread, |
| 1293 | * waits for the request to complete, and returns the result. |
| 1294 | * @see #sendRequestAsync |
| 1295 | */ |
| 1296 | private Object sendRequest( |
| 1297 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1298 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1299 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1300 | } |
| 1301 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1302 | MainThreadRequest request = null; |
| 1303 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1304 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1305 | } else if (phone != null) { |
| 1306 | request = new MainThreadRequest(argument, phone, workSource); |
| 1307 | } else { |
| 1308 | request = new MainThreadRequest(argument, subId, workSource); |
| 1309 | } |
| 1310 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1311 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1312 | msg.sendToTarget(); |
| 1313 | |
| 1314 | // Wait for the request to complete |
| 1315 | synchronized (request) { |
| 1316 | while (request.result == null) { |
| 1317 | try { |
| 1318 | request.wait(); |
| 1319 | } catch (InterruptedException e) { |
| 1320 | // Do nothing, go back and wait until the request is complete |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | return request.result; |
| 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1329 | * Posts the specified command to be executed on the main thread, and |
| 1330 | * returns immediately. |
| 1331 | * @see #sendRequest |
| 1332 | */ |
| 1333 | private void sendRequestAsync(int command) { |
| 1334 | mMainThreadHandler.sendEmptyMessage(command); |
| 1335 | } |
| 1336 | |
| 1337 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1338 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1339 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1340 | */ |
| 1341 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1342 | sendRequestAsync(command, argument, null, null); |
| 1343 | } |
| 1344 | |
| 1345 | /** |
| 1346 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1347 | * @see {@link #sendRequest(int,Object)} |
| 1348 | */ |
| 1349 | private void sendRequestAsync( |
| 1350 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1351 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1352 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1353 | msg.sendToTarget(); |
| 1354 | } |
| 1355 | |
| 1356 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1357 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1358 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1359 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1360 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1361 | synchronized (PhoneInterfaceManager.class) { |
| 1362 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1363 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1364 | } else { |
| 1365 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1366 | } |
| 1367 | return sInstance; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1372 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1373 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1374 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1375 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1376 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1377 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1378 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1379 | mTelephonySharedPreferences = |
| 1380 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1381 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1382 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1383 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1384 | publish(); |
| 1385 | } |
| 1386 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1387 | private Phone getDefaultPhone() { |
| 1388 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1389 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1390 | } |
| 1391 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1392 | private void publish() { |
| 1393 | if (DBG) log("publish: " + this); |
| 1394 | |
| 1395 | ServiceManager.addService("phone", this); |
| 1396 | } |
| 1397 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1398 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1399 | if (request.phone != null) { |
| 1400 | return request.phone; |
| 1401 | } else { |
| 1402 | return getPhoneFromSubId(request.subId); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | private Phone getPhoneFromSubId(int subId) { |
| 1407 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1408 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1409 | } |
| 1410 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1411 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1412 | Phone phone = getPhoneFromRequest(request); |
| 1413 | return phone == null ? null : |
| 1414 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1415 | } |
| 1416 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1417 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1418 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1419 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1421 | |
| 1422 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1423 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1426 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1427 | if (DBG) log("dial: " + number); |
| 1428 | // No permission check needed here: This is just a wrapper around the |
| 1429 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1430 | // the UI before it does anything. |
| 1431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1432 | final long identity = Binder.clearCallingIdentity(); |
| 1433 | try { |
| 1434 | String url = createTelUrl(number); |
| 1435 | if (url == null) { |
| 1436 | return; |
| 1437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1439 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1440 | PhoneConstants.State state = mCM.getState(subId); |
| 1441 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1442 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1443 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1444 | mApp.startActivity(intent); |
| 1445 | } |
| 1446 | } finally { |
| 1447 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1452 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1455 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1456 | if (DBG) log("call: " + number); |
| 1457 | |
| 1458 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1459 | // need to do a permission check since we're calling startActivity() |
| 1460 | // from the context of the phone app. |
| 1461 | enforceCallPermission(); |
| 1462 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1463 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1464 | != AppOpsManager.MODE_ALLOWED) { |
| 1465 | return; |
| 1466 | } |
| 1467 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1468 | final long identity = Binder.clearCallingIdentity(); |
| 1469 | try { |
| 1470 | String url = createTelUrl(number); |
| 1471 | if (url == null) { |
| 1472 | return; |
| 1473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1474 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1475 | boolean isValid = false; |
| 1476 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1477 | if (slist != null) { |
| 1478 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1479 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1480 | isValid = true; |
| 1481 | break; |
| 1482 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1483 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1484 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1485 | if (!isValid) { |
| 1486 | return; |
| 1487 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1488 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1489 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1490 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1491 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1492 | mApp.startActivity(intent); |
| 1493 | } finally { |
| 1494 | Binder.restoreCallingIdentity(identity); |
| 1495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1498 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1499 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1502 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1503 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1504 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1505 | } |
| 1506 | |
| 1507 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1508 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1511 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1512 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1513 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1514 | } |
| 1515 | |
| 1516 | /** {@hide} */ |
| 1517 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1518 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1521 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1522 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1523 | |
| 1524 | final long identity = Binder.clearCallingIdentity(); |
| 1525 | try { |
| 1526 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1527 | checkSimPin.start(); |
| 1528 | return checkSimPin.unlockSim(null, pin); |
| 1529 | } finally { |
| 1530 | Binder.restoreCallingIdentity(identity); |
| 1531 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1534 | /** {@hide} */ |
| 1535 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1536 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1539 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1540 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1541 | |
| 1542 | final long identity = Binder.clearCallingIdentity(); |
| 1543 | try { |
| 1544 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1545 | checkSimPuk.start(); |
| 1546 | return checkSimPuk.unlockSim(puk, pin); |
| 1547 | } finally { |
| 1548 | Binder.restoreCallingIdentity(identity); |
| 1549 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1553 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1554 | * a synchronous one. |
| 1555 | */ |
| 1556 | private static class UnlockSim extends Thread { |
| 1557 | |
| 1558 | private final IccCard mSimCard; |
| 1559 | |
| 1560 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1561 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1562 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1563 | |
| 1564 | // For replies from SimCard interface |
| 1565 | private Handler mHandler; |
| 1566 | |
| 1567 | // For async handler to identify request type |
| 1568 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1569 | |
| 1570 | public UnlockSim(IccCard simCard) { |
| 1571 | mSimCard = simCard; |
| 1572 | } |
| 1573 | |
| 1574 | @Override |
| 1575 | public void run() { |
| 1576 | Looper.prepare(); |
| 1577 | synchronized (UnlockSim.this) { |
| 1578 | mHandler = new Handler() { |
| 1579 | @Override |
| 1580 | public void handleMessage(Message msg) { |
| 1581 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1582 | switch (msg.what) { |
| 1583 | case SUPPLY_PIN_COMPLETE: |
| 1584 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1585 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1586 | mRetryCount = msg.arg1; |
| 1587 | if (ar.exception != null) { |
| 1588 | if (ar.exception instanceof CommandException && |
| 1589 | ((CommandException)(ar.exception)).getCommandError() |
| 1590 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1591 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1592 | } else { |
| 1593 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1594 | } |
| 1595 | } else { |
| 1596 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1597 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1598 | mDone = true; |
| 1599 | UnlockSim.this.notifyAll(); |
| 1600 | } |
| 1601 | break; |
| 1602 | } |
| 1603 | } |
| 1604 | }; |
| 1605 | UnlockSim.this.notifyAll(); |
| 1606 | } |
| 1607 | Looper.loop(); |
| 1608 | } |
| 1609 | |
| 1610 | /* |
| 1611 | * Use PIN or PUK to unlock SIM card |
| 1612 | * |
| 1613 | * If PUK is null, unlock SIM card with PIN |
| 1614 | * |
| 1615 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1616 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1617 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1618 | |
| 1619 | while (mHandler == null) { |
| 1620 | try { |
| 1621 | wait(); |
| 1622 | } catch (InterruptedException e) { |
| 1623 | Thread.currentThread().interrupt(); |
| 1624 | } |
| 1625 | } |
| 1626 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1627 | |
| 1628 | if (puk == null) { |
| 1629 | mSimCard.supplyPin(pin, callback); |
| 1630 | } else { |
| 1631 | mSimCard.supplyPuk(puk, pin, callback); |
| 1632 | } |
| 1633 | |
| 1634 | while (!mDone) { |
| 1635 | try { |
| 1636 | Log.d(LOG_TAG, "wait for done"); |
| 1637 | wait(); |
| 1638 | } catch (InterruptedException e) { |
| 1639 | // Restore the interrupted status |
| 1640 | Thread.currentThread().interrupt(); |
| 1641 | } |
| 1642 | } |
| 1643 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1644 | int[] resultArray = new int[2]; |
| 1645 | resultArray[0] = mResult; |
| 1646 | resultArray[1] = mRetryCount; |
| 1647 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1652 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1653 | |
| 1654 | } |
| 1655 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1656 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | // No permission check needed here: this call is harmless, and it's |
| 1658 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1659 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1660 | final long identity = Binder.clearCallingIdentity(); |
| 1661 | try { |
| 1662 | final Phone phone = getPhone(subId); |
| 1663 | if (phone != null) { |
| 1664 | phone.updateServiceLocation(); |
| 1665 | } |
| 1666 | } finally { |
| 1667 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1668 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1671 | @Override |
| 1672 | public boolean isRadioOn(String callingPackage) { |
| 1673 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1676 | @Override |
| 1677 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1679 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1680 | return false; |
| 1681 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1682 | |
| 1683 | final long identity = Binder.clearCallingIdentity(); |
| 1684 | try { |
| 1685 | return isRadioOnForSubscriber(subId); |
| 1686 | } finally { |
| 1687 | Binder.restoreCallingIdentity(identity); |
| 1688 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1692 | final long identity = Binder.clearCallingIdentity(); |
| 1693 | try { |
| 1694 | final Phone phone = getPhone(subId); |
| 1695 | if (phone != null) { |
| 1696 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1697 | } else { |
| 1698 | return false; |
| 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 | |
| 1705 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1706 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1707 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1708 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1709 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1710 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1711 | |
| 1712 | final long identity = Binder.clearCallingIdentity(); |
| 1713 | try { |
| 1714 | final Phone phone = getPhone(subId); |
| 1715 | if (phone != null) { |
| 1716 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1717 | } |
| 1718 | } finally { |
| 1719 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1720 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1724 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1727 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1728 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1729 | |
| 1730 | final long identity = Binder.clearCallingIdentity(); |
| 1731 | try { |
| 1732 | final Phone phone = getPhone(subId); |
| 1733 | if (phone == null) { |
| 1734 | return false; |
| 1735 | } |
| 1736 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1737 | toggleRadioOnOffForSubscriber(subId); |
| 1738 | } |
| 1739 | return true; |
| 1740 | } finally { |
| 1741 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1742 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1743 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1744 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1745 | public boolean needMobileRadioShutdown() { |
| 1746 | /* |
| 1747 | * If any of the Radios are available, it will need to be |
| 1748 | * shutdown. So return true if any Radio is available. |
| 1749 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1750 | final long identity = Binder.clearCallingIdentity(); |
| 1751 | try { |
| 1752 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1753 | Phone phone = PhoneFactory.getPhone(i); |
| 1754 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1755 | } |
| 1756 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1757 | return false; |
| 1758 | } finally { |
| 1759 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1760 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1763 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1764 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1765 | enforceModifyPermission(); |
| 1766 | |
| 1767 | final long identity = Binder.clearCallingIdentity(); |
| 1768 | try { |
| 1769 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1770 | logv("Shutting down Phone " + i); |
| 1771 | shutdownRadioUsingPhoneId(i); |
| 1772 | } |
| 1773 | } finally { |
| 1774 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1779 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1780 | if (phone != null && phone.isRadioAvailable()) { |
| 1781 | phone.shutdownRadio(); |
| 1782 | } |
| 1783 | } |
| 1784 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1786 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1787 | |
| 1788 | final long identity = Binder.clearCallingIdentity(); |
| 1789 | try { |
| 1790 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1791 | if (defaultPhone != null) { |
| 1792 | defaultPhone.setRadioPower(turnOn); |
| 1793 | return true; |
| 1794 | } else { |
| 1795 | loge("There's no default phone."); |
| 1796 | return false; |
| 1797 | } |
| 1798 | } finally { |
| 1799 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1800 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1803 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1804 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1805 | |
| 1806 | final long identity = Binder.clearCallingIdentity(); |
| 1807 | try { |
| 1808 | final Phone phone = getPhone(subId); |
| 1809 | if (phone != null) { |
| 1810 | phone.setRadioPower(turnOn); |
| 1811 | return true; |
| 1812 | } else { |
| 1813 | return false; |
| 1814 | } |
| 1815 | } finally { |
| 1816 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1820 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1821 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | public boolean enableDataConnectivity() { |
| 1823 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1824 | |
| 1825 | final long identity = Binder.clearCallingIdentity(); |
| 1826 | try { |
| 1827 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1828 | final Phone phone = getPhone(subId); |
| 1829 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1830 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1831 | return true; |
| 1832 | } else { |
| 1833 | return false; |
| 1834 | } |
| 1835 | } finally { |
| 1836 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1840 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1841 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | public boolean disableDataConnectivity() { |
| 1843 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1844 | |
| 1845 | final long identity = Binder.clearCallingIdentity(); |
| 1846 | try { |
| 1847 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1848 | final Phone phone = getPhone(subId); |
| 1849 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1850 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1851 | return true; |
| 1852 | } else { |
| 1853 | return false; |
| 1854 | } |
| 1855 | } finally { |
| 1856 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1857 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1860 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1861 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1862 | final long identity = Binder.clearCallingIdentity(); |
| 1863 | try { |
| 1864 | final Phone phone = getPhone(subId); |
| 1865 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1866 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1867 | } else { |
| 1868 | return false; |
| 1869 | } |
| 1870 | } finally { |
| 1871 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1872 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1876 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1879 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1880 | enforceCallPermission(); |
| 1881 | |
| 1882 | final long identity = Binder.clearCallingIdentity(); |
| 1883 | try { |
| 1884 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1885 | return; |
| 1886 | } |
| 1887 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1888 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1889 | } finally { |
| 1890 | Binder.restoreCallingIdentity(identity); |
| 1891 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1892 | }; |
| 1893 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1894 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1895 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1896 | |
| 1897 | final long identity = Binder.clearCallingIdentity(); |
| 1898 | try { |
| 1899 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1900 | return false; |
| 1901 | } |
| 1902 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1903 | } finally { |
| 1904 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1905 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1908 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1909 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1912 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1913 | final long identity = Binder.clearCallingIdentity(); |
| 1914 | try { |
| 1915 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1916 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1917 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1918 | } finally { |
| 1919 | Binder.restoreCallingIdentity(identity); |
| 1920 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1923 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1924 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1925 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1926 | } |
| 1927 | |
| 1928 | @Override |
| 1929 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1930 | final long identity = Binder.clearCallingIdentity(); |
| 1931 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1932 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1933 | if (phone != null) { |
| 1934 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1935 | } else { |
| 1936 | return PhoneConstantConversions.convertDataState( |
| 1937 | PhoneConstants.DataState.DISCONNECTED); |
| 1938 | } |
| 1939 | } finally { |
| 1940 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1941 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1944 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1945 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1946 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1947 | } |
| 1948 | |
| 1949 | @Override |
| 1950 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1951 | final long identity = Binder.clearCallingIdentity(); |
| 1952 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1953 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1954 | if (phone != null) { |
| 1955 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1956 | } else { |
| 1957 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1958 | } |
| 1959 | } finally { |
| 1960 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1961 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1965 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1966 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1967 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1968 | |
| 1969 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1970 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1971 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1972 | .setCallingPackage(callingPackage) |
| 1973 | .setCallingPid(Binder.getCallingPid()) |
| 1974 | .setCallingUid(Binder.getCallingUid()) |
| 1975 | .setMethod("getCellLocation") |
| 1976 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1977 | .build()); |
| 1978 | switch (locationResult) { |
| 1979 | case DENIED_HARD: |
| 1980 | throw new SecurityException("Not allowed to access cell location"); |
| 1981 | case DENIED_SOFT: |
| 1982 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1985 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1986 | final long identity = Binder.clearCallingIdentity(); |
| 1987 | try { |
| 1988 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1989 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1990 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1991 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1992 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1993 | return data; |
| 1994 | } finally { |
| 1995 | Binder.restoreCallingIdentity(identity); |
| 1996 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | @Override |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2000 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) { |
| 2001 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2002 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
| 2003 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2004 | mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) { |
| 2005 | return ""; |
| 2006 | } |
| 2007 | } |
| 2008 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2009 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2010 | // registered cell info, so return a NULL country instead. |
| 2011 | final long identity = Binder.clearCallingIdentity(); |
| 2012 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2013 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2014 | // Get default phone in this case. |
| 2015 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2016 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2017 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2018 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2019 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2020 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 2021 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 2022 | return ""; |
| 2023 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2024 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2025 | if (phone != null) { |
| 2026 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2027 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2028 | if (sst != null) { |
| 2029 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2030 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2031 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2032 | return lt.getCurrentCountry(); |
| 2033 | } else if (emergencyNumberTracker != null) { |
| 2034 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2035 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2036 | } |
| 2037 | } |
| 2038 | } |
| 2039 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2040 | } finally { |
| 2041 | Binder.restoreCallingIdentity(identity); |
| 2042 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2046 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2047 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2050 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2051 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2052 | mApp.enforceCallingOrSelfPermission( |
| 2053 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2054 | |
| 2055 | final long identity = Binder.clearCallingIdentity(); |
| 2056 | try { |
| 2057 | final Phone phone = getPhone(subId); |
| 2058 | if (phone != null) { |
| 2059 | phone.enableLocationUpdates(); |
| 2060 | } |
| 2061 | } finally { |
| 2062 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2063 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | @Override |
| 2067 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2068 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2071 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2072 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2073 | mApp.enforceCallingOrSelfPermission( |
| 2074 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2075 | |
| 2076 | final long identity = Binder.clearCallingIdentity(); |
| 2077 | try { |
| 2078 | final Phone phone = getPhone(subId); |
| 2079 | if (phone != null) { |
| 2080 | phone.disableLocationUpdates(); |
| 2081 | } |
| 2082 | } finally { |
| 2083 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2084 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2087 | /** |
| 2088 | * Returns the target SDK version number for a given package name. |
| 2089 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2090 | * This call MUST be invoked before clearing the calling UID. |
| 2091 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2092 | * @return target SDK if the package is found or INT_MAX. |
| 2093 | */ |
| 2094 | private int getTargetSdk(String packageName) { |
| 2095 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2096 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2097 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2098 | if (ai != null) return ai.targetSdkVersion; |
| 2099 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2100 | loge("Failed to get package info for pkg=" |
| 2101 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2102 | } |
| 2103 | return Integer.MAX_VALUE; |
| 2104 | } |
| 2105 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2106 | @Override |
| 2107 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2108 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2109 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2110 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2111 | throw new SecurityException( |
| 2112 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2113 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2114 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2115 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2116 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2117 | return null; |
| 2118 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2119 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2120 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2121 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2122 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2123 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2124 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2125 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2126 | for (CellInfo ci : info) { |
| 2127 | if (ci instanceof CellInfoGsm) { |
| 2128 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2129 | } else if (ci instanceof CellInfoWcdma) { |
| 2130 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2131 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2132 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2133 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2136 | private List<CellInfo> getCachedCellInfo() { |
| 2137 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2138 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2139 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2140 | if (info != null) cellInfos.addAll(info); |
| 2141 | } |
| 2142 | return cellInfos; |
| 2143 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2144 | |
| 2145 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2146 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2147 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2148 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2149 | |
| 2150 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2151 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2152 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2153 | .setCallingPackage(callingPackage) |
| 2154 | .setCallingPid(Binder.getCallingPid()) |
| 2155 | .setCallingUid(Binder.getCallingUid()) |
| 2156 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2157 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2158 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2159 | .build()); |
| 2160 | switch (locationResult) { |
| 2161 | case DENIED_HARD: |
| 2162 | throw new SecurityException("Not allowed to access cell info"); |
| 2163 | case DENIED_SOFT: |
| 2164 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2167 | final int targetSdk = getTargetSdk(callingPackage); |
| 2168 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2169 | return getCachedCellInfo(); |
| 2170 | } |
| 2171 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2172 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2173 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2174 | final long identity = Binder.clearCallingIdentity(); |
| 2175 | try { |
| 2176 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2177 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2178 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2179 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2180 | if (info != null) cellInfos.addAll(info); |
| 2181 | } |
| 2182 | return cellInfos; |
| 2183 | } finally { |
| 2184 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2188 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2189 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2190 | requestCellInfoUpdateInternal( |
| 2191 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2192 | } |
| 2193 | |
| 2194 | @Override |
| 2195 | public void requestCellInfoUpdateWithWorkSource( |
| 2196 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2197 | enforceModifyPermission(); |
| 2198 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2199 | } |
| 2200 | |
| 2201 | private void requestCellInfoUpdateInternal( |
| 2202 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2203 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2204 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2205 | |
| 2206 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2207 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2208 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2209 | .setCallingPackage(callingPackage) |
| 2210 | .setCallingPid(Binder.getCallingPid()) |
| 2211 | .setCallingUid(Binder.getCallingUid()) |
| 2212 | .setMethod("requestCellInfoUpdate") |
| 2213 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2214 | .build()); |
| 2215 | switch (locationResult) { |
| 2216 | case DENIED_HARD: |
| 2217 | throw new SecurityException("Not allowed to access cell info"); |
| 2218 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2219 | try { |
| 2220 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2221 | } catch (RemoteException re) { |
| 2222 | // Drop without consequences |
| 2223 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2224 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2227 | |
| 2228 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2229 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2230 | |
| 2231 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2232 | } |
| 2233 | |
| 2234 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2236 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2237 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2238 | |
| 2239 | final long identity = Binder.clearCallingIdentity(); |
| 2240 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2241 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2242 | } finally { |
| 2243 | Binder.restoreCallingIdentity(identity); |
| 2244 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2247 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2248 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2249 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2250 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2251 | return null; |
| 2252 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2253 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2254 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2255 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2256 | return null; |
| 2257 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | |
| 2259 | final long identity = Binder.clearCallingIdentity(); |
| 2260 | try { |
| 2261 | return phone.getImei(); |
| 2262 | } finally { |
| 2263 | Binder.restoreCallingIdentity(identity); |
| 2264 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2268 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2269 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2270 | String tac = null; |
| 2271 | if (phone != null) { |
| 2272 | String imei = phone.getImei(); |
| 2273 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2274 | } |
| 2275 | return tac; |
| 2276 | } |
| 2277 | |
| 2278 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2279 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2280 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2281 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2282 | return null; |
| 2283 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2284 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2285 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2286 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2287 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2288 | return null; |
| 2289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2290 | |
| 2291 | final long identity = Binder.clearCallingIdentity(); |
| 2292 | try { |
| 2293 | return phone.getMeid(); |
| 2294 | } finally { |
| 2295 | Binder.restoreCallingIdentity(identity); |
| 2296 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2300 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2301 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2302 | String manufacturerCode = null; |
| 2303 | if (phone != null) { |
| 2304 | String meid = phone.getMeid(); |
| 2305 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2306 | } |
| 2307 | return manufacturerCode; |
| 2308 | } |
| 2309 | |
| 2310 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2311 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2312 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2313 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2314 | return null; |
| 2315 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2316 | int subId = phone.getSubId(); |
| 2317 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2318 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2319 | return null; |
| 2320 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2321 | |
| 2322 | final long identity = Binder.clearCallingIdentity(); |
| 2323 | try { |
| 2324 | return phone.getDeviceSvn(); |
| 2325 | } finally { |
| 2326 | Binder.restoreCallingIdentity(identity); |
| 2327 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2330 | @Override |
| 2331 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2332 | final long identity = Binder.clearCallingIdentity(); |
| 2333 | try { |
| 2334 | final Phone phone = getPhone(subId); |
| 2335 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2336 | } finally { |
| 2337 | Binder.restoreCallingIdentity(identity); |
| 2338 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | @Override |
| 2342 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2343 | final long identity = Binder.clearCallingIdentity(); |
| 2344 | try { |
| 2345 | final Phone phone = getPhone(subId); |
| 2346 | return phone == null ? null : phone.getCarrierName(); |
| 2347 | } finally { |
| 2348 | Binder.restoreCallingIdentity(identity); |
| 2349 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2350 | } |
| 2351 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2352 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2353 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2354 | final long identity = Binder.clearCallingIdentity(); |
| 2355 | try { |
| 2356 | final Phone phone = getPhone(subId); |
| 2357 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2358 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2359 | } finally { |
| 2360 | Binder.restoreCallingIdentity(identity); |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2365 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2366 | final long identity = Binder.clearCallingIdentity(); |
| 2367 | try { |
| 2368 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2369 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2370 | } finally { |
| 2371 | Binder.restoreCallingIdentity(identity); |
| 2372 | } |
| 2373 | } |
| 2374 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2375 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2376 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2377 | if (!isSubscriptionMccMnc) { |
| 2378 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2379 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2380 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2381 | if (phone == null) { |
| 2382 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2383 | } |
| 2384 | final long identity = Binder.clearCallingIdentity(); |
| 2385 | try { |
| 2386 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2387 | } finally { |
| 2388 | Binder.restoreCallingIdentity(identity); |
| 2389 | } |
| 2390 | } |
| 2391 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | // |
| 2393 | // Internal helper methods. |
| 2394 | // |
| 2395 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2396 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2398 | * |
| 2399 | * @throws SecurityException if the caller does not have the required permission |
| 2400 | */ |
| 2401 | private void enforceModifyPermission() { |
| 2402 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2403 | } |
| 2404 | |
| 2405 | /** |
| 2406 | * Make sure the caller has the CALL_PHONE permission. |
| 2407 | * |
| 2408 | * @throws SecurityException if the caller does not have the required permission |
| 2409 | */ |
| 2410 | private void enforceCallPermission() { |
| 2411 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2412 | } |
| 2413 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2414 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2415 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2416 | "ConnectivityService"); |
| 2417 | } |
| 2418 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2419 | private String createTelUrl(String number) { |
| 2420 | if (TextUtils.isEmpty(number)) { |
| 2421 | return null; |
| 2422 | } |
| 2423 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2424 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2427 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2429 | } |
| 2430 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2431 | private static void logv(String msg) { |
| 2432 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2433 | } |
| 2434 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2435 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2437 | } |
| 2438 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2439 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2440 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2441 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2444 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2445 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | final long identity = Binder.clearCallingIdentity(); |
| 2447 | try { |
| 2448 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2449 | if (phone == null) { |
| 2450 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2451 | } else { |
| 2452 | return phone.getPhoneType(); |
| 2453 | } |
| 2454 | } finally { |
| 2455 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2456 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | /** |
| 2460 | * Returns the CDMA ERI icon index to display |
| 2461 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2462 | @Override |
| 2463 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2464 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2467 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2468 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2470 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2471 | return -1; |
| 2472 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2473 | |
| 2474 | final long identity = Binder.clearCallingIdentity(); |
| 2475 | try { |
| 2476 | final Phone phone = getPhone(subId); |
| 2477 | if (phone != null) { |
| 2478 | return phone.getCdmaEriIconIndex(); |
| 2479 | } else { |
| 2480 | return -1; |
| 2481 | } |
| 2482 | } finally { |
| 2483 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | /** |
| 2488 | * Returns the CDMA ERI icon mode, |
| 2489 | * 0 - ON |
| 2490 | * 1 - FLASHING |
| 2491 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2492 | @Override |
| 2493 | public int getCdmaEriIconMode(String callingPackage) { |
| 2494 | return getCdmaEriIconModeForSubscriber(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 getCdmaEriIconModeForSubscriber(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, "getCdmaEriIconModeForSubscriber")) { |
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.getCdmaEriIconMode(); |
| 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 text, |
| 2519 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2520 | @Override |
| 2521 | public String getCdmaEriText(String callingPackage) { |
| 2522 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2525 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2526 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2527 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2528 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2529 | return null; |
| 2530 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2531 | |
| 2532 | final long identity = Binder.clearCallingIdentity(); |
| 2533 | try { |
| 2534 | final Phone phone = getPhone(subId); |
| 2535 | if (phone != null) { |
| 2536 | return phone.getCdmaEriText(); |
| 2537 | } else { |
| 2538 | return null; |
| 2539 | } |
| 2540 | } finally { |
| 2541 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2542 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2546 | * Returns the CDMA MDN. |
| 2547 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2548 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2549 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2550 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2551 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2552 | |
| 2553 | final long identity = Binder.clearCallingIdentity(); |
| 2554 | try { |
| 2555 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2556 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2557 | return phone.getLine1Number(); |
| 2558 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2559 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | return null; |
| 2561 | } |
| 2562 | } finally { |
| 2563 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | /** |
| 2568 | * Returns the CDMA MIN. |
| 2569 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2570 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2571 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2572 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2573 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2574 | |
| 2575 | final long identity = Binder.clearCallingIdentity(); |
| 2576 | try { |
| 2577 | final Phone phone = getPhone(subId); |
| 2578 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2579 | return phone.getCdmaMin(); |
| 2580 | } else { |
| 2581 | return null; |
| 2582 | } |
| 2583 | } finally { |
| 2584 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2585 | } |
| 2586 | } |
| 2587 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2588 | @Override |
| 2589 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2590 | INumberVerificationCallback callback, String callingPackage) { |
| 2591 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2592 | != PERMISSION_GRANTED) { |
| 2593 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2594 | } |
| 2595 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2596 | |
| 2597 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2598 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2599 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2600 | } |
| 2601 | |
| 2602 | if (range == null) { |
| 2603 | throw new NullPointerException("Range must be non-null"); |
| 2604 | } |
| 2605 | |
| 2606 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2607 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2608 | |
| 2609 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2610 | } |
| 2611 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2612 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2613 | * Returns true if CDMA provisioning needs to run. |
| 2614 | */ |
| 2615 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | final long identity = Binder.clearCallingIdentity(); |
| 2617 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2618 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
| 2621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2625 | * Sets the voice mail number of a given subId. |
| 2626 | */ |
| 2627 | @Override |
| 2628 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2629 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2630 | |
| 2631 | final long identity = Binder.clearCallingIdentity(); |
| 2632 | try { |
| 2633 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2634 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2635 | return success; |
| 2636 | } finally { |
| 2637 | Binder.restoreCallingIdentity(identity); |
| 2638 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2639 | } |
| 2640 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2641 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2642 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2643 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2644 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2645 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2646 | throw new SecurityException("caller must be system dialer"); |
| 2647 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2648 | |
| 2649 | final long identity = Binder.clearCallingIdentity(); |
| 2650 | try { |
| 2651 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2652 | if (phoneAccountHandle == null) { |
| 2653 | return null; |
| 2654 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2655 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | } finally { |
| 2657 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2658 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2662 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2663 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2664 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2665 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2666 | return null; |
| 2667 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2669 | final long identity = Binder.clearCallingIdentity(); |
| 2670 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2671 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(identity); |
| 2674 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2678 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2679 | VisualVoicemailSmsFilterSettings settings) { |
| 2680 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | |
| 2682 | final long identity = Binder.clearCallingIdentity(); |
| 2683 | try { |
| 2684 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2685 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | } finally { |
| 2687 | Binder.restoreCallingIdentity(identity); |
| 2688 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2692 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2693 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2694 | |
| 2695 | final long identity = Binder.clearCallingIdentity(); |
| 2696 | try { |
| 2697 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2698 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2699 | } finally { |
| 2700 | Binder.restoreCallingIdentity(identity); |
| 2701 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2705 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2706 | String callingPackage, int subId) { |
| 2707 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2708 | |
| 2709 | final long identity = Binder.clearCallingIdentity(); |
| 2710 | try { |
| 2711 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2712 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | } finally { |
| 2714 | Binder.restoreCallingIdentity(identity); |
| 2715 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2719 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2720 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2721 | |
| 2722 | final long identity = Binder.clearCallingIdentity(); |
| 2723 | try { |
| 2724 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2725 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2726 | } finally { |
| 2727 | Binder.restoreCallingIdentity(identity); |
| 2728 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | @Override |
| 2732 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2733 | String number, int port, String text, PendingIntent sentIntent) { |
| 2734 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2735 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2736 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2737 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2738 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2739 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2740 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2741 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2742 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2743 | * Sets the voice activation state of a given subId. |
| 2744 | */ |
| 2745 | @Override |
| 2746 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2748 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2749 | |
| 2750 | final long identity = Binder.clearCallingIdentity(); |
| 2751 | try { |
| 2752 | final Phone phone = getPhone(subId); |
| 2753 | if (phone != null) { |
| 2754 | phone.setVoiceActivationState(activationState); |
| 2755 | } else { |
| 2756 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2757 | } |
| 2758 | } finally { |
| 2759 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | /** |
| 2764 | * Sets the data activation state of a given subId. |
| 2765 | */ |
| 2766 | @Override |
| 2767 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2768 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2769 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2770 | |
| 2771 | final long identity = Binder.clearCallingIdentity(); |
| 2772 | try { |
| 2773 | final Phone phone = getPhone(subId); |
| 2774 | if (phone != null) { |
| 2775 | phone.setDataActivationState(activationState); |
| 2776 | } else { |
| 2777 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2778 | } |
| 2779 | } finally { |
| 2780 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | /** |
| 2785 | * Returns the voice activation state of a given subId. |
| 2786 | */ |
| 2787 | @Override |
| 2788 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2789 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2790 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2791 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2792 | final long identity = Binder.clearCallingIdentity(); |
| 2793 | try { |
| 2794 | if (phone != null) { |
| 2795 | return phone.getVoiceActivationState(); |
| 2796 | } else { |
| 2797 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2798 | } |
| 2799 | } finally { |
| 2800 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | /** |
| 2805 | * Returns the data activation state of a given subId. |
| 2806 | */ |
| 2807 | @Override |
| 2808 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2809 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2810 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2811 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2812 | final long identity = Binder.clearCallingIdentity(); |
| 2813 | try { |
| 2814 | if (phone != null) { |
| 2815 | return phone.getDataActivationState(); |
| 2816 | } else { |
| 2817 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2818 | } |
| 2819 | } finally { |
| 2820 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2821 | } |
| 2822 | } |
| 2823 | |
| 2824 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2825 | * Returns the unread count of voicemails for a subId |
| 2826 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2827 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2828 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2829 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2830 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2831 | return 0; |
| 2832 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2833 | final long identity = Binder.clearCallingIdentity(); |
| 2834 | try { |
| 2835 | final Phone phone = getPhone(subId); |
| 2836 | if (phone != null) { |
| 2837 | return phone.getVoiceMessageCount(); |
| 2838 | } else { |
| 2839 | return 0; |
| 2840 | } |
| 2841 | } finally { |
| 2842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2843 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2847 | * returns true, if the device is in a state where both voice and data |
| 2848 | * are supported simultaneously. This can change based on location or network condition. |
| 2849 | */ |
| 2850 | @Override |
| 2851 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | final long identity = Binder.clearCallingIdentity(); |
| 2853 | try { |
| 2854 | final Phone phone = getPhone(subId); |
| 2855 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2856 | } finally { |
| 2857 | Binder.restoreCallingIdentity(identity); |
| 2858 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2862 | * Send the dialer code if called from the current default dialer or the caller has |
| 2863 | * carrier privilege. |
| 2864 | * @param inputCode The dialer code to send |
| 2865 | */ |
| 2866 | @Override |
| 2867 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2868 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2869 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2870 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2871 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2872 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2873 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2874 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2875 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | |
| 2877 | final long identity = Binder.clearCallingIdentity(); |
| 2878 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2879 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2880 | } finally { |
| 2881 | Binder.restoreCallingIdentity(identity); |
| 2882 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2883 | } |
| 2884 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2885 | @Override |
| 2886 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2887 | if (!isActiveSubscription(subId)) { |
| 2888 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2889 | } |
| 2890 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2891 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2892 | } |
| 2893 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2894 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2895 | public boolean isInEmergencySmsMode() { |
| 2896 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2897 | final long identity = Binder.clearCallingIdentity(); |
| 2898 | try { |
| 2899 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2900 | if (phone.isInEmergencySmsMode()) { |
| 2901 | return true; |
| 2902 | } |
| 2903 | } |
| 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(identity); |
| 2906 | } |
| 2907 | return false; |
| 2908 | } |
| 2909 | |
| 2910 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2911 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2912 | throws RemoteException { |
| 2913 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2914 | final long token = Binder.clearCallingIdentity(); |
| 2915 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2916 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2917 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2918 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2919 | } catch (ImsException e) { |
| 2920 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2921 | } finally { |
| 2922 | Binder.restoreCallingIdentity(token); |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2927 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2928 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2929 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2930 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2931 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2932 | final long token = Binder.clearCallingIdentity(); |
| 2933 | try { |
| 2934 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2935 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 2936 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2937 | } catch (ImsException e) { |
| 2938 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2939 | + "is inactive, ignoring unregister."); |
| 2940 | // If the subscription is no longer active, just return, since the callback |
| 2941 | // will already have been removed internally. |
| 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(token); |
| 2944 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2948 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2949 | throws RemoteException { |
| 2950 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2951 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2952 | final long token = Binder.clearCallingIdentity(); |
| 2953 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2954 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2955 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2956 | } catch (ImsException e) { |
| 2957 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2958 | } finally { |
| 2959 | Binder.restoreCallingIdentity(token); |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2964 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2965 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2966 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2967 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2968 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2969 | |
| 2970 | final long token = Binder.clearCallingIdentity(); |
| 2971 | try { |
| 2972 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 2973 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2974 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2975 | } catch (ImsException e) { |
| 2976 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2977 | + "is inactive, ignoring unregister."); |
| 2978 | // If the subscription is no longer active, just return, since the callback |
| 2979 | // will already have been removed internally. |
| 2980 | } finally { |
| 2981 | Binder.restoreCallingIdentity(token); |
| 2982 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2986 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2987 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2988 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2989 | final long token = Binder.clearCallingIdentity(); |
| 2990 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2991 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2992 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2993 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2994 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2995 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2996 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2997 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2998 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2999 | } finally { |
| 3000 | Binder.restoreCallingIdentity(token); |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3005 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3006 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3007 | final long token = Binder.clearCallingIdentity(); |
| 3008 | try { |
| 3009 | Phone phone = getPhone(subId); |
| 3010 | if (phone == null) return false; |
| 3011 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3012 | } finally { |
| 3013 | Binder.restoreCallingIdentity(token); |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | @Override |
| 3018 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 3019 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 3020 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3021 | final long token = Binder.clearCallingIdentity(); |
| 3022 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3023 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3024 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3025 | } catch (ImsException e) { |
| 3026 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(token); |
| 3029 | } |
| 3030 | } |
| 3031 | |
| 3032 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3033 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3034 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3035 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3036 | final long identity = Binder.clearCallingIdentity(); |
| 3037 | try { |
| 3038 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3039 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3040 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3041 | } catch (ImsException e) { |
| 3042 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3043 | } finally { |
| 3044 | Binder.restoreCallingIdentity(identity); |
| 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3049 | public boolean isVtSettingEnabled(int subId) { |
| 3050 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3051 | final long identity = Binder.clearCallingIdentity(); |
| 3052 | try { |
| 3053 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3054 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3055 | } catch (ImsException e) { |
| 3056 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3057 | } finally { |
| 3058 | Binder.restoreCallingIdentity(identity); |
| 3059 | } |
| 3060 | } |
| 3061 | |
| 3062 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3063 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3064 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3065 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3066 | final long identity = Binder.clearCallingIdentity(); |
| 3067 | try { |
| 3068 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3069 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3070 | } catch (ImsException e) { |
| 3071 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3072 | } finally { |
| 3073 | Binder.restoreCallingIdentity(identity); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | @Override |
| 3078 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3079 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3080 | final long identity = Binder.clearCallingIdentity(); |
| 3081 | try { |
| 3082 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3083 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3084 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3085 | } catch (ImsException e) { |
| 3086 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3093 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3095 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3096 | final long identity = Binder.clearCallingIdentity(); |
| 3097 | try { |
| 3098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3099 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3100 | } catch (ImsException e) { |
| 3101 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
| 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | @Override |
| 3108 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3109 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
| 3112 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3113 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3114 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3115 | } catch (ImsException e) { |
| 3116 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3117 | } finally { |
| 3118 | Binder.restoreCallingIdentity(identity); |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3123 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3125 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3126 | final long identity = Binder.clearCallingIdentity(); |
| 3127 | try { |
| 3128 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3129 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3130 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3131 | } catch (ImsException e) { |
| 3132 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3133 | } finally { |
| 3134 | Binder.restoreCallingIdentity(identity); |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | @Override |
| 3139 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3141 | "setVoWiFiNonPersistent"); |
| 3142 | final long identity = Binder.clearCallingIdentity(); |
| 3143 | try { |
| 3144 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3145 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3146 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3147 | } catch (ImsException e) { |
| 3148 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3149 | } finally { |
| 3150 | Binder.restoreCallingIdentity(identity); |
| 3151 | } |
| 3152 | } |
| 3153 | |
| 3154 | @Override |
| 3155 | public int getVoWiFiModeSetting(int subId) { |
| 3156 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3157 | final long identity = Binder.clearCallingIdentity(); |
| 3158 | try { |
| 3159 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3160 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3161 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3162 | } catch (ImsException e) { |
| 3163 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3164 | } finally { |
| 3165 | Binder.restoreCallingIdentity(identity); |
| 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | @Override |
| 3170 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3172 | "setVoWiFiModeSetting"); |
| 3173 | final long identity = Binder.clearCallingIdentity(); |
| 3174 | try { |
| 3175 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3176 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3177 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3178 | } catch (ImsException e) { |
| 3179 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3180 | } finally { |
| 3181 | Binder.restoreCallingIdentity(identity); |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | @Override |
| 3186 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3187 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3188 | final long identity = Binder.clearCallingIdentity(); |
| 3189 | try { |
| 3190 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3191 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3192 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3193 | } catch (ImsException e) { |
| 3194 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3195 | } finally { |
| 3196 | Binder.restoreCallingIdentity(identity); |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | @Override |
| 3201 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3202 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3203 | "setVoWiFiRoamingModeSetting"); |
| 3204 | final long identity = Binder.clearCallingIdentity(); |
| 3205 | try { |
| 3206 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3207 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3208 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3209 | } catch (ImsException e) { |
| 3210 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3211 | } finally { |
| 3212 | Binder.restoreCallingIdentity(identity); |
| 3213 | } |
| 3214 | } |
| 3215 | |
| 3216 | @Override |
| 3217 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3218 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3219 | "setRttCapabilityEnabled"); |
| 3220 | final long identity = Binder.clearCallingIdentity(); |
| 3221 | try { |
| 3222 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3223 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3224 | } catch (ImsException e) { |
| 3225 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3226 | } finally { |
| 3227 | Binder.restoreCallingIdentity(identity); |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | @Override |
| 3232 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3233 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3234 | final long identity = Binder.clearCallingIdentity(); |
| 3235 | try { |
| 3236 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3237 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3238 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3239 | } catch (ImsException e) { |
| 3240 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3241 | } finally { |
| 3242 | Binder.restoreCallingIdentity(identity); |
| 3243 | } |
| 3244 | } |
| 3245 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3246 | @Override |
| 3247 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3248 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3249 | final long identity = Binder.clearCallingIdentity(); |
| 3250 | try { |
| 3251 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3252 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3253 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3254 | } catch (ImsException e) { |
| 3255 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3256 | } finally { |
| 3257 | Binder.restoreCallingIdentity(identity); |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | @Override |
| 3262 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3263 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3264 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3265 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3266 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3267 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3268 | try { |
| 3269 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3270 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3271 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3272 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3273 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3274 | + "is inactive, ignoring unregister."); |
| 3275 | // If the subscription is no longer active, just return, since the callback will already |
| 3276 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(identity); |
| 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3283 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3284 | boolean isProvisioned) { |
| 3285 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3286 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3287 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3288 | } |
| 3289 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3290 | "setProvisioningStatusForCapability"); |
| 3291 | final long identity = Binder.clearCallingIdentity(); |
| 3292 | try { |
| 3293 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3294 | Phone phone = getPhone(subId); |
| 3295 | if (phone == null) { |
| 3296 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3297 | + subId); |
| 3298 | return; |
| 3299 | } |
| 3300 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3301 | return; |
| 3302 | } |
| 3303 | |
| 3304 | // this capability requires provisioning, route to the correct API. |
| 3305 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3306 | switch (capability) { |
| 3307 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3308 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3309 | ims.setVolteProvisioned(isProvisioned); |
| 3310 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3311 | ims.setWfcProvisioned(isProvisioned); |
| 3312 | } |
| 3313 | break; |
| 3314 | } |
| 3315 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3316 | // There is currently no difference in VT provisioning type. |
| 3317 | ims.setVtProvisioned(isProvisioned); |
| 3318 | break; |
| 3319 | } |
| 3320 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3321 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3322 | // change the capability of the feature instead if needed. |
| 3323 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3324 | == isProvisioned) { |
| 3325 | // No change in provisioning. |
| 3326 | return; |
| 3327 | } |
| 3328 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3329 | try { |
| 3330 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3331 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3332 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3333 | + ", Exception" + e.getMessage()); |
| 3334 | } |
| 3335 | break; |
| 3336 | } |
| 3337 | default: { |
| 3338 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3339 | + capability + "', which does not require provisioning."); |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | } finally { |
| 3344 | Binder.restoreCallingIdentity(identity); |
| 3345 | } |
| 3346 | } |
| 3347 | |
| 3348 | @Override |
| 3349 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3350 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3351 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3352 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3353 | } |
| 3354 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3355 | final long identity = Binder.clearCallingIdentity(); |
| 3356 | try { |
| 3357 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3358 | Phone phone = getPhone(subId); |
| 3359 | if (phone == null) { |
| 3360 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3361 | + subId); |
| 3362 | // We will fail with "true" as the provisioning status because this is the default |
| 3363 | // if we do not require provisioning. |
| 3364 | return true; |
| 3365 | } |
| 3366 | |
| 3367 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3368 | return true; |
| 3369 | } |
| 3370 | |
| 3371 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3372 | switch (capability) { |
| 3373 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3374 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3375 | return ims.isVolteProvisionedOnDevice(); |
| 3376 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3377 | return ims.isWfcProvisionedOnDevice(); |
| 3378 | } |
| 3379 | // This should never happen, since we are checking tech above to make sure it |
| 3380 | // is either LTE or IWLAN. |
| 3381 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3382 | + "capability."); |
| 3383 | } |
| 3384 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3385 | // There is currently no difference in VT provisioning type. |
| 3386 | return ims.isVtProvisionedOnDevice(); |
| 3387 | } |
| 3388 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3389 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3390 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3391 | } |
| 3392 | default: { |
| 3393 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3394 | + capability + "', which does not require provisioning."); |
| 3395 | } |
| 3396 | } |
| 3397 | |
| 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(identity); |
| 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | @Override |
| 3404 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3405 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3406 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3407 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3408 | } |
| 3409 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3410 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3411 | return (provisionedBits & capability) > 0; |
| 3412 | } |
| 3413 | |
| 3414 | @Override |
| 3415 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3416 | boolean isProvisioned) { |
| 3417 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3418 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3419 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3420 | } |
| 3421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3422 | "setProvisioningStatusForCapability"); |
| 3423 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3424 | // If the current provisioning status for capability already matches isProvisioned, |
| 3425 | // do nothing. |
| 3426 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3427 | return; |
| 3428 | } |
| 3429 | if (isProvisioned) { |
| 3430 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3431 | } else { |
| 3432 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | /** |
| 3437 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3438 | * technology. The bitfield should mirror the bitfield defined by |
| 3439 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3440 | */ |
| 3441 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3442 | String key = getMmTelProvisioningKey(subId, tech); |
| 3443 | // Default is no capabilities are provisioned. |
| 3444 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3445 | } |
| 3446 | |
| 3447 | /** |
| 3448 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3449 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3450 | * technology specified. |
| 3451 | * |
| 3452 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3453 | */ |
| 3454 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3455 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3456 | String key = getMmTelProvisioningKey(subId, tech); |
| 3457 | editor.putInt(key, newField); |
| 3458 | editor.commit(); |
| 3459 | } |
| 3460 | |
| 3461 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3462 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3463 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3464 | } |
| 3465 | |
| 3466 | /** |
| 3467 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3468 | * carrier associated with the subscription id. |
| 3469 | */ |
| 3470 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3471 | int capability) { |
| 3472 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3473 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3474 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3475 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3476 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3477 | false); |
| 3478 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3479 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3480 | |
| 3481 | // First check to make sure that the capability requires provisioning. |
| 3482 | switch (capability) { |
| 3483 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3484 | // intentional fallthrough |
| 3485 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3486 | if (requireVoiceVtProvisioning) { |
| 3487 | // Voice and Video requires provisioning |
| 3488 | return true; |
| 3489 | } |
| 3490 | break; |
| 3491 | } |
| 3492 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3493 | if (requireUtProvisioning) { |
| 3494 | // UT requires provisioning |
| 3495 | return true; |
| 3496 | } |
| 3497 | break; |
| 3498 | } |
| 3499 | } |
| 3500 | return false; |
| 3501 | } |
| 3502 | |
| 3503 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3504 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3505 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3506 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3507 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3508 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3509 | final long identity = Binder.clearCallingIdentity(); |
| 3510 | try { |
| 3511 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3512 | int slotId = getSlotIndex(subId); |
| 3513 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3514 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3515 | + subId + "' for key:" + key); |
| 3516 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3517 | } |
| 3518 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3519 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3520 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3521 | + subId + "' for key:" + key); |
| 3522 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3523 | } finally { |
| 3524 | Binder.restoreCallingIdentity(identity); |
| 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | @Override |
| 3529 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3530 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3531 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3532 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3533 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3534 | final long identity = Binder.clearCallingIdentity(); |
| 3535 | try { |
| 3536 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3537 | int slotId = getSlotIndex(subId); |
| 3538 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3539 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3540 | + subId + "' for key:" + key); |
| 3541 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3542 | } |
| 3543 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3544 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3545 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3546 | + subId + "' for key:" + key); |
| 3547 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3548 | } finally { |
| 3549 | Binder.restoreCallingIdentity(identity); |
| 3550 | } |
| 3551 | } |
| 3552 | |
| 3553 | @Override |
| 3554 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3555 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3556 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3557 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3559 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3560 | final long identity = Binder.clearCallingIdentity(); |
| 3561 | try { |
| 3562 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3563 | int slotId = getSlotIndex(subId); |
| 3564 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3565 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3566 | + subId + "' for key:" + key); |
| 3567 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3568 | } |
| 3569 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3570 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3571 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3572 | + "' for key:" + key); |
| 3573 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3574 | } finally { |
| 3575 | Binder.restoreCallingIdentity(identity); |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | @Override |
| 3580 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3581 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3582 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3583 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3585 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3586 | final long identity = Binder.clearCallingIdentity(); |
| 3587 | try { |
| 3588 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3589 | int slotId = getSlotIndex(subId); |
| 3590 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3591 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3592 | + subId + "' for key:" + key); |
| 3593 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3594 | } |
| 3595 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3596 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3597 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3598 | + "' for key:" + key); |
| 3599 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3600 | } finally { |
| 3601 | Binder.restoreCallingIdentity(identity); |
| 3602 | } |
| 3603 | } |
| 3604 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3605 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3606 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3607 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3608 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3609 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3610 | } |
| 3611 | return slotId; |
| 3612 | } |
| 3613 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3614 | private int getSlotIndex(int subId) { |
| 3615 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3616 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3617 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3618 | } |
| 3619 | return slotId; |
| 3620 | } |
| 3621 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3622 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3623 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3624 | */ |
| 3625 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3626 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3627 | final int targetSdk = getTargetSdk(callingPackage); |
| 3628 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
| 3629 | return getDataNetworkTypeForSubscriber(subId, callingPackage); |
| 3630 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3631 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3632 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3633 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3634 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3636 | final long identity = Binder.clearCallingIdentity(); |
| 3637 | try { |
| 3638 | final Phone phone = getPhone(subId); |
| 3639 | if (phone != null) { |
| 3640 | return phone.getServiceState().getDataNetworkType(); |
| 3641 | } else { |
| 3642 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3643 | } |
| 3644 | } finally { |
| 3645 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3646 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * Returns the data network type |
| 3651 | */ |
| 3652 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3653 | public int getDataNetworkType(String callingPackage) { |
| 3654 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | /** |
| 3658 | * Returns the data network type for a subId |
| 3659 | */ |
| 3660 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3661 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3662 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3663 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3664 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3665 | } |
| 3666 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3667 | final long identity = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | final Phone phone = getPhone(subId); |
| 3670 | if (phone != null) { |
| 3671 | return phone.getServiceState().getDataNetworkType(); |
| 3672 | } else { |
| 3673 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3674 | } |
| 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3677 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3681 | * Returns the Voice network type for a subId |
| 3682 | */ |
| 3683 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3684 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3685 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3686 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3687 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3688 | } |
| 3689 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3690 | final long identity = Binder.clearCallingIdentity(); |
| 3691 | try { |
| 3692 | final Phone phone = getPhone(subId); |
| 3693 | if (phone != null) { |
| 3694 | return phone.getServiceState().getVoiceNetworkType(); |
| 3695 | } else { |
| 3696 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3697 | } |
| 3698 | } finally { |
| 3699 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3700 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | /** |
| 3704 | * @return true if a ICC card is present |
| 3705 | */ |
| 3706 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3707 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3708 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3709 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3713 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3714 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3715 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3716 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3717 | final long identity = Binder.clearCallingIdentity(); |
| 3718 | try { |
| 3719 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3720 | if (phone != null) { |
| 3721 | return phone.getIccCard().hasIccCard(); |
| 3722 | } else { |
| 3723 | return false; |
| 3724 | } |
| 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3727 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | /** |
| 3731 | * Return if the current radio is LTE on CDMA. This |
| 3732 | * is a tri-state return value as for a period of time |
| 3733 | * the mode may be unknown. |
| 3734 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3735 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3736 | * @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] | 3737 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3738 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3739 | @Override |
| 3740 | public int getLteOnCdmaMode(String callingPackage) { |
| 3741 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3744 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3745 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3746 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3747 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3748 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3749 | } |
| 3750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | final long identity = Binder.clearCallingIdentity(); |
| 3752 | try { |
| 3753 | final Phone phone = getPhone(subId); |
| 3754 | if (phone == null) { |
| 3755 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3756 | } else { |
| 3757 | return phone.getLteOnCdmaMode(); |
| 3758 | } |
| 3759 | } finally { |
| 3760 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3761 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3764 | /** |
| 3765 | * {@hide} |
| 3766 | * Returns Default subId, 0 in the case of single standby. |
| 3767 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3768 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3769 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3770 | } |
| 3771 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3772 | private int getSlotForDefaultSubscription() { |
| 3773 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3774 | } |
| 3775 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3776 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3777 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3778 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3779 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3780 | private boolean isActiveSubscription(int subId) { |
| 3781 | return mSubscriptionController.isActiveSubId(subId); |
| 3782 | } |
| 3783 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3784 | /** |
| 3785 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3786 | */ |
| 3787 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3788 | final long identity = Binder.clearCallingIdentity(); |
| 3789 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3790 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3791 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3792 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3793 | } finally { |
| 3794 | Binder.restoreCallingIdentity(identity); |
| 3795 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | /** |
| 3799 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3800 | */ |
| 3801 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | final long identity = Binder.clearCallingIdentity(); |
| 3803 | try { |
| 3804 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3805 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3806 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3807 | } finally { |
| 3808 | Binder.restoreCallingIdentity(identity); |
| 3809 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3810 | } |
| 3811 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3812 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3813 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3814 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3815 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3816 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3817 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3818 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3819 | if (phoneId == -1) { |
| 3820 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3821 | + " does not correspond to an active phone"); |
| 3822 | } |
| 3823 | return PhoneFactory.getPhone(phoneId); |
| 3824 | } |
| 3825 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3826 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3827 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3828 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3829 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3830 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3832 | if (DBG) { |
| 3833 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3834 | } |
| 3835 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3836 | p2); |
| 3837 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3838 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3839 | |
| 3840 | @Override |
| 3841 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3842 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3843 | enforceModifyPermission(); |
| 3844 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3845 | if (DBG) { |
| 3846 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3847 | } |
| 3848 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3849 | callingPackage, aid, p2); |
| 3850 | } |
| 3851 | |
| 3852 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3853 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3854 | final long identity = Binder.clearCallingIdentity(); |
| 3855 | try { |
| 3856 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3857 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3858 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3859 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3860 | if (bestComponent == null |
| 3861 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3862 | loge("The calling package is not allowed to access ISD-R."); |
| 3863 | throw new SecurityException( |
| 3864 | "The calling package is not allowed to access ISD-R."); |
| 3865 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3866 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3867 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3868 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3869 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3870 | null /* workSource */); |
| 3871 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3872 | return response; |
| 3873 | } finally { |
| 3874 | Binder.restoreCallingIdentity(identity); |
| 3875 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3879 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3881 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3882 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3883 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3884 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3885 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3886 | @Override |
| 3887 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3888 | enforceModifyPermission(); |
| 3889 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3890 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3891 | channel); |
| 3892 | } |
| 3893 | |
| 3894 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3895 | final long identity = Binder.clearCallingIdentity(); |
| 3896 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3897 | if (channel < 0) { |
| 3898 | return false; |
| 3899 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3900 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3901 | null /* workSource */); |
| 3902 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3903 | return success; |
| 3904 | } finally { |
| 3905 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3906 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3910 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3911 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3913 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3914 | if (DBG) { |
| 3915 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3916 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3917 | + p3 + " data=" + data); |
| 3918 | } |
| 3919 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3920 | command, p1, p2, p3, data); |
| 3921 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3922 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3923 | @Override |
| 3924 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3925 | int command, int p1, int p2, int p3, String data) { |
| 3926 | enforceModifyPermission(); |
| 3927 | if (DBG) { |
| 3928 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3929 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3930 | + p3 + " data=" + data); |
| 3931 | } |
| 3932 | return iccTransmitApduLogicalChannelWithPermission( |
| 3933 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3934 | data); |
| 3935 | } |
| 3936 | |
| 3937 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3938 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3939 | final long identity = Binder.clearCallingIdentity(); |
| 3940 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3941 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3942 | return ""; |
| 3943 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3944 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3945 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3946 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3947 | null /* workSource */); |
| 3948 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3949 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 | // Append the returned status code to the end of the response payload. |
| 3951 | String s = Integer.toHexString( |
| 3952 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3953 | if (response.payload != null) { |
| 3954 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3955 | } |
| 3956 | return s; |
| 3957 | } finally { |
| 3958 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3959 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3960 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3961 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3962 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3963 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3964 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3965 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3966 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3967 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3968 | if (DBG) { |
| 3969 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3970 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3971 | } |
| 3972 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3973 | cla, command, p1, p2, p3, data); |
| 3974 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3975 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3976 | @Override |
| 3977 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3978 | int command, int p1, int p2, int p3, String data) { |
| 3979 | enforceModifyPermission(); |
| 3980 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3981 | if (DBG) { |
| 3982 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3983 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3984 | + " data=" + data); |
| 3985 | } |
| 3986 | |
| 3987 | return iccTransmitApduBasicChannelWithPermission( |
| 3988 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3989 | p2, p3, data); |
| 3990 | } |
| 3991 | |
| 3992 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3993 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3994 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3995 | final long identity = Binder.clearCallingIdentity(); |
| 3996 | try { |
| 3997 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3998 | && TextUtils.equals(ISDR_AID, data)) { |
| 3999 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4000 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4001 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4002 | if (bestComponent == null |
| 4003 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4004 | loge("The calling package is not allowed to select ISD-R."); |
| 4005 | throw new SecurityException( |
| 4006 | "The calling package is not allowed to select ISD-R."); |
| 4007 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4008 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4009 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4010 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4011 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4012 | null /* workSource */); |
| 4013 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4014 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4015 | // Append the returned status code to the end of the response payload. |
| 4016 | String s = Integer.toHexString( |
| 4017 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4018 | if (response.payload != null) { |
| 4019 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4020 | } |
| 4021 | return s; |
| 4022 | } finally { |
| 4023 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4024 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4028 | 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] | 4029 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4030 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4031 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4032 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4033 | final long identity = Binder.clearCallingIdentity(); |
| 4034 | try { |
| 4035 | if (DBG) { |
| 4036 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4037 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4038 | } |
| 4039 | |
| 4040 | IccIoResult response = |
| 4041 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4042 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4043 | subId); |
| 4044 | |
| 4045 | if (DBG) { |
| 4046 | log("Exchange SIM_IO [R]" + response); |
| 4047 | } |
| 4048 | |
| 4049 | byte[] result = null; |
| 4050 | int length = 2; |
| 4051 | if (response.payload != null) { |
| 4052 | length = 2 + response.payload.length; |
| 4053 | result = new byte[length]; |
| 4054 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4055 | } else { |
| 4056 | result = new byte[length]; |
| 4057 | } |
| 4058 | |
| 4059 | result[length - 1] = (byte) response.sw2; |
| 4060 | result[length - 2] = (byte) response.sw1; |
| 4061 | return result; |
| 4062 | } finally { |
| 4063 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4064 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4067 | /** |
| 4068 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4069 | * on a particular subscription |
| 4070 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4071 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 4072 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4073 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 4074 | return null; |
| 4075 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4076 | |
| 4077 | final long identity = Binder.clearCallingIdentity(); |
| 4078 | try { |
| 4079 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4080 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4081 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4082 | return null; |
| 4083 | } |
| 4084 | Object response = sendRequest( |
| 4085 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4086 | if (response instanceof String[]) { |
| 4087 | return (String[]) response; |
| 4088 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame^] | 4089 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4090 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4091 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4092 | } finally { |
| 4093 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4094 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4095 | } |
| 4096 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame^] | 4097 | /** |
| 4098 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4099 | * subscription. |
| 4100 | * |
| 4101 | * @param subId the id of the subscription. |
| 4102 | * @param appType the uicc app type, must be USIM or SIM. |
| 4103 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4104 | * @param callingPackage the op Package name. |
| 4105 | * @return number of fplmns that is successfully written to the SIM. |
| 4106 | */ |
| 4107 | public int setForbiddenPlmns( |
| 4108 | int subId, int appType, List<String> fplmns, String callingPackage) { |
| 4109 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 4110 | mApp, subId, callingPackage, "setForbiddenPlmns")) { |
| 4111 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4112 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4113 | } |
| 4114 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4115 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4116 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4117 | } |
| 4118 | if (fplmns == null) { |
| 4119 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4120 | } |
| 4121 | for (String fplmn : fplmns) { |
| 4122 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4123 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4124 | } |
| 4125 | } |
| 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | Object response = sendRequest( |
| 4129 | CMD_SET_FORBIDDEN_PLMNS, |
| 4130 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4131 | subId); |
| 4132 | return (int) response; |
| 4133 | } finally { |
| 4134 | Binder.restoreCallingIdentity(identity); |
| 4135 | } |
| 4136 | } |
| 4137 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4138 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4139 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4141 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4143 | final long identity = Binder.clearCallingIdentity(); |
| 4144 | try { |
| 4145 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4146 | if (response.payload == null) { |
| 4147 | return ""; |
| 4148 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4149 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4150 | // Append the returned status code to the end of the response payload. |
| 4151 | String s = Integer.toHexString( |
| 4152 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4153 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4154 | return s; |
| 4155 | } finally { |
| 4156 | Binder.restoreCallingIdentity(identity); |
| 4157 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4160 | /** |
| 4161 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4162 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4163 | * |
| 4164 | * @param itemID the ID of the item to read |
| 4165 | * @return the NV item as a String, or null on error. |
| 4166 | */ |
| 4167 | @Override |
| 4168 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4169 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4170 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4171 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4172 | |
| 4173 | final long identity = Binder.clearCallingIdentity(); |
| 4174 | try { |
| 4175 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4176 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4178 | return value; |
| 4179 | } finally { |
| 4180 | Binder.restoreCallingIdentity(identity); |
| 4181 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | /** |
| 4185 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4186 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4187 | * |
| 4188 | * @param itemID the ID of the item to read |
| 4189 | * @param itemValue the value to write, as a String |
| 4190 | * @return true on success; false on any failure |
| 4191 | */ |
| 4192 | @Override |
| 4193 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4194 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4195 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4196 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4197 | |
| 4198 | final long identity = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4201 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4202 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4203 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4204 | return success; |
| 4205 | } finally { |
| 4206 | Binder.restoreCallingIdentity(identity); |
| 4207 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | /** |
| 4211 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4212 | * Used for device configuration by some CDMA operators. |
| 4213 | * |
| 4214 | * @param preferredRoamingList byte array containing the new PRL |
| 4215 | * @return true on success; false on any failure |
| 4216 | */ |
| 4217 | @Override |
| 4218 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4219 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4220 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4221 | |
| 4222 | final long identity = Binder.clearCallingIdentity(); |
| 4223 | try { |
| 4224 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4225 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4226 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4227 | return success; |
| 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(identity); |
| 4230 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4234 | * 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] | 4235 | * Used for device configuration by some CDMA operators. |
| 4236 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4237 | * @param slotIndex - device slot. |
| 4238 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4239 | * @return true on success; false on any failure |
| 4240 | */ |
| 4241 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4242 | public boolean resetModemConfig(int slotIndex) { |
| 4243 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4244 | if (phone != null) { |
| 4245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4246 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4247 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4248 | final long identity = Binder.clearCallingIdentity(); |
| 4249 | try { |
| 4250 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4251 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4252 | return success; |
| 4253 | } finally { |
| 4254 | Binder.restoreCallingIdentity(identity); |
| 4255 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4256 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4257 | return false; |
| 4258 | } |
| 4259 | |
| 4260 | /** |
| 4261 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4262 | * |
| 4263 | * @param slotIndex - device slot. |
| 4264 | * |
| 4265 | * @return true on success; false on any failure |
| 4266 | */ |
| 4267 | @Override |
| 4268 | public boolean rebootModem(int slotIndex) { |
| 4269 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4270 | if (phone != null) { |
| 4271 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4272 | mApp, phone.getSubId(), "rebootModem"); |
| 4273 | |
| 4274 | final long identity = Binder.clearCallingIdentity(); |
| 4275 | try { |
| 4276 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4277 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4278 | return success; |
| 4279 | } finally { |
| 4280 | Binder.restoreCallingIdentity(identity); |
| 4281 | } |
| 4282 | } |
| 4283 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4284 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4285 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4286 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4287 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4288 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4289 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4290 | return new String[0]; |
| 4291 | } |
| 4292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4293 | final long identity = Binder.clearCallingIdentity(); |
| 4294 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4295 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4296 | } finally { |
| 4297 | Binder.restoreCallingIdentity(identity); |
| 4298 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4301 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4302 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4303 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4304 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4305 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4306 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4307 | |
| 4308 | final long identity = Binder.clearCallingIdentity(); |
| 4309 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4310 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4311 | if (resolver == null) { |
| 4312 | // may happen if the device does not support IMS. |
| 4313 | return; |
| 4314 | } |
| 4315 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
| 4318 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4322 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4323 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4324 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4325 | public void disableIms(int slotId) { |
| 4326 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4327 | |
| 4328 | final long identity = Binder.clearCallingIdentity(); |
| 4329 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4330 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4331 | if (resolver == null) { |
| 4332 | // may happen if the device does not support IMS. |
| 4333 | return; |
| 4334 | } |
| 4335 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4336 | } finally { |
| 4337 | Binder.restoreCallingIdentity(identity); |
| 4338 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | /** |
| 4342 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4343 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4344 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4345 | */ |
| 4346 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4347 | IImsServiceFeatureCallback callback) { |
| 4348 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4349 | |
| 4350 | final long identity = Binder.clearCallingIdentity(); |
| 4351 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4352 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4353 | if (resolver == null) { |
| 4354 | // may happen if the device does not support IMS. |
| 4355 | return null; |
| 4356 | } |
| 4357 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
| 4360 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | /** |
| 4364 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4365 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4366 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4367 | * listener for feature updates. |
| 4368 | */ |
| 4369 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4370 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4371 | |
| 4372 | final long identity = Binder.clearCallingIdentity(); |
| 4373 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4374 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4375 | if (resolver == null) { |
| 4376 | // may happen if the device does not support IMS. |
| 4377 | return null; |
| 4378 | } |
| 4379 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4380 | } finally { |
| 4381 | Binder.restoreCallingIdentity(identity); |
| 4382 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4383 | } |
| 4384 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4385 | /** |
| 4386 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4387 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4388 | */ |
| 4389 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4390 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4391 | |
| 4392 | final long identity = Binder.clearCallingIdentity(); |
| 4393 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4394 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4395 | if (resolver == null) { |
| 4396 | // may happen if the device does not support IMS. |
| 4397 | return null; |
| 4398 | } |
| 4399 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4400 | } finally { |
| 4401 | Binder.restoreCallingIdentity(identity); |
| 4402 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4403 | } |
| 4404 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4405 | /** |
| 4406 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4407 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4408 | */ |
| 4409 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4410 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4411 | |
| 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4414 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4415 | if (resolver == null) { |
| 4416 | // may happen if the device does not support IMS. |
| 4417 | return null; |
| 4418 | } |
| 4419 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4420 | } finally { |
| 4421 | Binder.restoreCallingIdentity(identity); |
| 4422 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4423 | } |
| 4424 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4425 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4426 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4427 | * |
| 4428 | * @param slotId the slot ID that the ImsService should bind for. |
| 4429 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4430 | * ImsService is the device default ImsService. |
| 4431 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4432 | * to. |
| 4433 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4434 | * @hide |
| 4435 | */ |
| 4436 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4437 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4439 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4440 | "setImsService"); |
| 4441 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | final long identity = Binder.clearCallingIdentity(); |
| 4443 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4444 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4445 | if (resolver == null) { |
| 4446 | // may happen if the device does not support IMS. |
| 4447 | return false; |
| 4448 | } |
| 4449 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4450 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4451 | } finally { |
| 4452 | Binder.restoreCallingIdentity(identity); |
| 4453 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4454 | } |
| 4455 | |
| 4456 | /** |
| 4457 | * Return the ImsService configuration. |
| 4458 | * |
| 4459 | * @param slotId The slot that the ImsService is associated with. |
| 4460 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4461 | * the device default. |
| 4462 | * @return the package name of the ImsService configuration. |
| 4463 | */ |
| 4464 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4465 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4466 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4467 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4468 | "getImsService"); |
| 4469 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4470 | final long identity = Binder.clearCallingIdentity(); |
| 4471 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4472 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4473 | if (resolver == null) { |
| 4474 | // may happen if the device does not support IMS. |
| 4475 | return ""; |
| 4476 | } |
| 4477 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | } finally { |
| 4479 | Binder.restoreCallingIdentity(identity); |
| 4480 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4481 | } |
| 4482 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4483 | public void setImsRegistrationState(boolean registered) { |
| 4484 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | |
| 4486 | final long identity = Binder.clearCallingIdentity(); |
| 4487 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4488 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4489 | } finally { |
| 4490 | Binder.restoreCallingIdentity(identity); |
| 4491 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4495 | * Set the network selection mode to automatic. |
| 4496 | * |
| 4497 | */ |
| 4498 | @Override |
| 4499 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4500 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4501 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4502 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4503 | if (!isActiveSubscription(subId)) { |
| 4504 | return; |
| 4505 | } |
| 4506 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4507 | final long identity = Binder.clearCallingIdentity(); |
| 4508 | try { |
| 4509 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4510 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(identity); |
| 4513 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4514 | } |
| 4515 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4516 | /** |
| 4517 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4518 | * |
| 4519 | * @param subId the id of the subscription. |
| 4520 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4521 | * the operator to attach to. |
| 4522 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4523 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4524 | * normal network selection next time. |
| 4525 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4526 | */ |
| 4527 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4528 | public boolean setNetworkSelectionModeManual( |
| 4529 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4530 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4531 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4532 | |
| 4533 | if (!isActiveSubscription(subId)) { |
| 4534 | return false; |
| 4535 | } |
| 4536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4537 | final long identity = Binder.clearCallingIdentity(); |
| 4538 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4539 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4541 | if (DBG) { |
| 4542 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4543 | + " operator: " + operatorInfo); |
| 4544 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4545 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4546 | } finally { |
| 4547 | Binder.restoreCallingIdentity(identity); |
| 4548 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | /** |
| 4552 | * Scans for available networks. |
| 4553 | */ |
| 4554 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4555 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4556 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4557 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4558 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4559 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4560 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4561 | .setCallingPackage(callingPackage) |
| 4562 | .setCallingPid(Binder.getCallingPid()) |
| 4563 | .setCallingUid(Binder.getCallingUid()) |
| 4564 | .setMethod("getCellNetworkScanResults") |
| 4565 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4566 | .build()); |
| 4567 | switch (locationResult) { |
| 4568 | case DENIED_HARD: |
| 4569 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4570 | case DENIED_SOFT: |
| 4571 | return null; |
| 4572 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4573 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4574 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4575 | try { |
| 4576 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4577 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4578 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4579 | } finally { |
| 4580 | Binder.restoreCallingIdentity(identity); |
| 4581 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4585 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4586 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4587 | * @param subId id of the subscription |
| 4588 | * @param request contains the radio access networks with bands/channels to scan |
| 4589 | * @param messenger callback messenger for scan results or errors |
| 4590 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4591 | * @return the id of the requested scan which can be used to stop the scan. |
| 4592 | */ |
| 4593 | @Override |
| 4594 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4595 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4597 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4598 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4599 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4600 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4601 | .setCallingPackage(callingPackage) |
| 4602 | .setCallingPid(Binder.getCallingPid()) |
| 4603 | .setCallingUid(Binder.getCallingUid()) |
| 4604 | .setMethod("requestNetworkScan") |
| 4605 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4606 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4607 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4608 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4609 | if (e != null) { |
| 4610 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4611 | throw e; |
| 4612 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4613 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4614 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4615 | } |
| 4616 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4617 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4618 | int callingUid = Binder.getCallingUid(); |
| 4619 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4620 | final long identity = Binder.clearCallingIdentity(); |
| 4621 | try { |
| 4622 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4623 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4624 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4625 | } finally { |
| 4626 | Binder.restoreCallingIdentity(identity); |
| 4627 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4630 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4631 | NetworkScanRequest request, int subId) { |
| 4632 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4633 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4634 | boolean hasNetworkScanPermission = |
| 4635 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4636 | == PERMISSION_GRANTED; |
| 4637 | |
| 4638 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4639 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4640 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4644 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4645 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4646 | return new SecurityException("Specific channels must not be" |
| 4647 | + " scanned without location access."); |
| 4648 | } |
| 4649 | } |
| 4650 | } |
| 4651 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4652 | return null; |
| 4653 | } |
| 4654 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4655 | /** |
| 4656 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4657 | * |
| 4658 | * @param subId id of the subscription |
| 4659 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4660 | */ |
| 4661 | @Override |
| 4662 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4664 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4665 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4666 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4667 | final long identity = Binder.clearCallingIdentity(); |
| 4668 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4669 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4670 | } finally { |
| 4671 | Binder.restoreCallingIdentity(identity); |
| 4672 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4676 | * Get the calculated preferred network type. |
| 4677 | * Used for debugging incorrect network type. |
| 4678 | * |
| 4679 | * @return the preferred network type, defined in RILConstants.java. |
| 4680 | */ |
| 4681 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4682 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4683 | final Phone defaultPhone = getDefaultPhone(); |
| 4684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4685 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4686 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4687 | } |
| 4688 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4689 | final long identity = Binder.clearCallingIdentity(); |
| 4690 | try { |
| 4691 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4692 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4693 | } finally { |
| 4694 | Binder.restoreCallingIdentity(identity); |
| 4695 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4699 | * Get the preferred network type. |
| 4700 | * Used for device configuration by some CDMA operators. |
| 4701 | * |
| 4702 | * @return the preferred network type, defined in RILConstants.java. |
| 4703 | */ |
| 4704 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4705 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4706 | TelephonyPermissions |
| 4707 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4708 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4709 | |
| 4710 | final long identity = Binder.clearCallingIdentity(); |
| 4711 | try { |
| 4712 | if (DBG) log("getPreferredNetworkType"); |
| 4713 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4714 | int networkType = (result != null ? result[0] : -1); |
| 4715 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4716 | return networkType; |
| 4717 | } finally { |
| 4718 | Binder.restoreCallingIdentity(identity); |
| 4719 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | /** |
| 4723 | * Set the preferred network type. |
| 4724 | * Used for device configuration by some CDMA operators. |
| 4725 | * |
| 4726 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4727 | * @return true on success; false on any failure. |
| 4728 | */ |
| 4729 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4730 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4731 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4732 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4733 | |
| 4734 | final long identity = Binder.clearCallingIdentity(); |
| 4735 | try { |
| 4736 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4737 | Boolean success = (Boolean) sendRequest( |
| 4738 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4739 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4740 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4741 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4742 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4743 | } |
| 4744 | return success; |
| 4745 | } finally { |
| 4746 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4747 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4748 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4749 | |
| 4750 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4751 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4752 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4753 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4754 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4755 | * @hide |
| 4756 | */ |
| 4757 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4758 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4759 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4760 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4761 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4762 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4763 | if (phone != null) { |
| 4764 | return phone.hasMatchedTetherApnSetting(); |
| 4765 | } else { |
| 4766 | return false; |
| 4767 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4768 | } finally { |
| 4769 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4770 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4771 | } |
| 4772 | |
| 4773 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4774 | * Set mobile data enabled |
| 4775 | * Used by the user through settings etc to turn on/off mobile data |
| 4776 | * |
| 4777 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4778 | */ |
| 4779 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4780 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4782 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4783 | |
| 4784 | final long identity = Binder.clearCallingIdentity(); |
| 4785 | try { |
| 4786 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4787 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4788 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4789 | if (phone != null) { |
| 4790 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4791 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4792 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4793 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4794 | } |
| 4795 | } finally { |
| 4796 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4797 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4801 | * Get the user enabled state of Mobile Data. |
| 4802 | * |
| 4803 | * TODO: remove and use isUserDataEnabled. |
| 4804 | * This can't be removed now because some vendor codes |
| 4805 | * calls through ITelephony directly while they should |
| 4806 | * use TelephonyManager. |
| 4807 | * |
| 4808 | * @return true on enabled |
| 4809 | */ |
| 4810 | @Override |
| 4811 | public boolean getDataEnabled(int subId) { |
| 4812 | return isUserDataEnabled(subId); |
| 4813 | } |
| 4814 | |
| 4815 | /** |
| 4816 | * Get whether mobile data is enabled per user setting. |
| 4817 | * |
| 4818 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4819 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4820 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4821 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4822 | * |
| 4823 | * @return {@code true} if data is enabled else {@code false} |
| 4824 | */ |
| 4825 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4826 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4827 | try { |
| 4828 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4829 | null); |
| 4830 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4831 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4832 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4833 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | |
| 4835 | final long identity = Binder.clearCallingIdentity(); |
| 4836 | try { |
| 4837 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4838 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4839 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4840 | if (phone != null) { |
| 4841 | boolean retVal = phone.isUserDataEnabled(); |
| 4842 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4843 | return retVal; |
| 4844 | } else { |
| 4845 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4846 | return false; |
| 4847 | } |
| 4848 | } finally { |
| 4849 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4850 | } |
| 4851 | } |
| 4852 | |
| 4853 | /** |
| 4854 | * Get whether mobile data is enabled. |
| 4855 | * |
| 4856 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4857 | * whether mobile data is actually enabled. |
| 4858 | * |
| 4859 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4860 | * |
| 4861 | * @return {@code true} if data is enabled else {@code false} |
| 4862 | */ |
| 4863 | @Override |
| 4864 | public boolean isDataEnabled(int subId) { |
| 4865 | try { |
| 4866 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4867 | null); |
| 4868 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4869 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4870 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4871 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4872 | |
| 4873 | final long identity = Binder.clearCallingIdentity(); |
| 4874 | try { |
| 4875 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4876 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4877 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4878 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4879 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4880 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4881 | return retVal; |
| 4882 | } else { |
| 4883 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4884 | return false; |
| 4885 | } |
| 4886 | } finally { |
| 4887 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4888 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4889 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4890 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4891 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 4892 | Phone phone) { |
| 4893 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4894 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4895 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4896 | || subController == null) return privilegeFromSim; |
| 4897 | |
| 4898 | int uid = Binder.getCallingUid(); |
| 4899 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 4900 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 4901 | |
| 4902 | final long identity = Binder.clearCallingIdentity(); |
| 4903 | try { |
| 4904 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4905 | SubscriptionManager subManager = (SubscriptionManager) |
| 4906 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4907 | for (String pkg : packages) { |
| 4908 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 4909 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4910 | } |
| 4911 | } |
| 4912 | return privilegeFromSim; |
| 4913 | } finally { |
| 4914 | Binder.restoreCallingIdentity(identity); |
| 4915 | } |
| 4916 | } |
| 4917 | |
| 4918 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 4919 | String pkgName) { |
| 4920 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 4921 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 4922 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 4923 | || subController == null) return privilegeFromSim; |
| 4924 | |
| 4925 | final long identity = Binder.clearCallingIdentity(); |
| 4926 | try { |
| 4927 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 4928 | SubscriptionManager subManager = (SubscriptionManager) |
| 4929 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 4930 | return subManager.canManageSubscription(subInfo, pkgName) |
| 4931 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 4932 | } finally { |
| 4933 | Binder.restoreCallingIdentity(identity); |
| 4934 | } |
| 4935 | } |
| 4936 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4937 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4938 | public int getCarrierPrivilegeStatus(int subId) { |
| 4939 | final Phone phone = getPhone(subId); |
| 4940 | if (phone == null) { |
| 4941 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4942 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4943 | } |
| 4944 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4945 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4946 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4947 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4948 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4949 | |
| 4950 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4951 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 4952 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4953 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4954 | |
| 4955 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4956 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4957 | final Phone phone = getPhone(subId); |
| 4958 | if (phone == null) { |
| 4959 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4960 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4961 | } |
| 4962 | UiccProfile profile = |
| 4963 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4964 | if (profile == null) { |
| 4965 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4966 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4967 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4968 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4969 | profile.getCarrierPrivilegeStatusForUid( |
| 4970 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4974 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4975 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4976 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 4980 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4981 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4982 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4983 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4984 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 4985 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 4986 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 4987 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | @Override |
| 4991 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4992 | if (TextUtils.isEmpty(pkgName)) |
| 4993 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4994 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4995 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4996 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4997 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4998 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4999 | continue; |
| 5000 | } |
| 5001 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5002 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5003 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5004 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5005 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5006 | break; |
| 5007 | } |
| 5008 | } |
| 5009 | |
| 5010 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5011 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5012 | |
| 5013 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5014 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5015 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5016 | loge("phoneId " + phoneId + " is not valid."); |
| 5017 | return null; |
| 5018 | } |
| 5019 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5020 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 5021 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5022 | return null ; |
| 5023 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5024 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5025 | } |
| 5026 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5027 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5028 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5029 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5030 | List<String> privilegedPackages = new ArrayList<>(); |
| 5031 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5032 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5033 | // has UICC in that slot. |
| 5034 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5035 | if (card.hasCarrierPrivilegeRules()) { |
| 5036 | if (packages == null) { |
| 5037 | // Only check packages in user 0 for now |
| 5038 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5039 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5040 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5041 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5042 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5043 | } |
| 5044 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5045 | PackageInfo pkgInfo = packages.get(p); |
| 5046 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5047 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5048 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5049 | privilegedPackages.add(pkgInfo.packageName); |
| 5050 | } |
| 5051 | } |
| 5052 | } |
| 5053 | } |
| 5054 | return privilegedPackages; |
| 5055 | } |
| 5056 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5057 | @Override |
| 5058 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 5059 | List<String> privilegedPackages = new ArrayList<>(); |
| 5060 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5061 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5062 | } |
| 5063 | return privilegedPackages; |
| 5064 | } |
| 5065 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5066 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5067 | final Phone phone = getPhone(subId); |
| 5068 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5069 | if (card == null) { |
| 5070 | loge("getIccId: No UICC"); |
| 5071 | return null; |
| 5072 | } |
| 5073 | String iccId = card.getIccId(); |
| 5074 | if (TextUtils.isEmpty(iccId)) { |
| 5075 | loge("getIccId: ICC ID is null or empty."); |
| 5076 | return null; |
| 5077 | } |
| 5078 | return iccId; |
| 5079 | } |
| 5080 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5081 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5082 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5083 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5084 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5085 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5086 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5087 | final long identity = Binder.clearCallingIdentity(); |
| 5088 | try { |
| 5089 | final String iccId = getIccId(subId); |
| 5090 | final Phone phone = getPhone(subId); |
| 5091 | if (phone == null) { |
| 5092 | return false; |
| 5093 | } |
| 5094 | final String subscriberId = phone.getSubscriberId(); |
| 5095 | |
| 5096 | if (DBG_MERGE) { |
| 5097 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5098 | + subscriberId + " to " + number); |
| 5099 | } |
| 5100 | |
| 5101 | if (TextUtils.isEmpty(iccId)) { |
| 5102 | return false; |
| 5103 | } |
| 5104 | |
| 5105 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5106 | |
| 5107 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5108 | if (alphaTag == null) { |
| 5109 | editor.remove(alphaTagPrefKey); |
| 5110 | } else { |
| 5111 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5112 | } |
| 5113 | |
| 5114 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5115 | // track all merged IMSIs based on line number |
| 5116 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5117 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5118 | if (number == null) { |
| 5119 | editor.remove(numberPrefKey); |
| 5120 | editor.remove(subscriberPrefKey); |
| 5121 | } else { |
| 5122 | editor.putString(numberPrefKey, number); |
| 5123 | editor.putString(subscriberPrefKey, subscriberId); |
| 5124 | } |
| 5125 | |
| 5126 | editor.commit(); |
| 5127 | return true; |
| 5128 | } finally { |
| 5129 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5130 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5134 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5135 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5136 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5137 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5138 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5139 | return null; |
| 5140 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5141 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5142 | final long identity = Binder.clearCallingIdentity(); |
| 5143 | try { |
| 5144 | String iccId = getIccId(subId); |
| 5145 | if (iccId != null) { |
| 5146 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5147 | if (DBG_MERGE) { |
| 5148 | log("getLine1NumberForDisplay returning " |
| 5149 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5150 | } |
| 5151 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5152 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5154 | return null; |
| 5155 | } finally { |
| 5156 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5157 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5161 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5162 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5163 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5164 | return null; |
| 5165 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5166 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5167 | final long identity = Binder.clearCallingIdentity(); |
| 5168 | try { |
| 5169 | String iccId = getIccId(subId); |
| 5170 | if (iccId != null) { |
| 5171 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5172 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5173 | } |
| 5174 | return null; |
| 5175 | } finally { |
| 5176 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5177 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5178 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5179 | |
| 5180 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5181 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5182 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5183 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5184 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5185 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 5186 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5187 | return null; |
| 5188 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5189 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5190 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5191 | // the process, where TelephonyManager was instantiated. |
| 5192 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5193 | final long identity = Binder.clearCallingIdentity(); |
| 5194 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5195 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5196 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5197 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5198 | |
| 5199 | // Figure out what subscribers are currently active |
| 5200 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5201 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5202 | // Only consider subs which match the current subId |
| 5203 | // This logic can be simplified. See b/131189269 for progress. |
| 5204 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5205 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5206 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | |
| 5208 | // First pass, find a number override for an active subscriber |
| 5209 | String mergeNumber = null; |
| 5210 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5211 | for (String key : prefs.keySet()) { |
| 5212 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5213 | final String subscriberId = (String) prefs.get(key); |
| 5214 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5215 | final String iccId = key.substring( |
| 5216 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5217 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5218 | mergeNumber = (String) prefs.get(numberKey); |
| 5219 | if (DBG_MERGE) { |
| 5220 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5221 | + " for active subscriber " + subscriberId); |
| 5222 | } |
| 5223 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5224 | break; |
| 5225 | } |
| 5226 | } |
| 5227 | } |
| 5228 | } |
| 5229 | |
| 5230 | // Shortcut when no active merged subscribers |
| 5231 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5232 | return null; |
| 5233 | } |
| 5234 | |
| 5235 | // Second pass, find all subscribers under that line override |
| 5236 | final ArraySet<String> result = new ArraySet<>(); |
| 5237 | for (String key : prefs.keySet()) { |
| 5238 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5239 | final String number = (String) prefs.get(key); |
| 5240 | if (mergeNumber.equals(number)) { |
| 5241 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5242 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5243 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5244 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5245 | result.add(subscriberId); |
| 5246 | } |
| 5247 | } |
| 5248 | } |
| 5249 | } |
| 5250 | |
| 5251 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5252 | Arrays.sort(resultArray); |
| 5253 | if (DBG_MERGE) { |
| 5254 | Slog.d(LOG_TAG, |
| 5255 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5256 | } |
| 5257 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5260 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5264 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 5265 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 5266 | |
| 5267 | final long identity = Binder.clearCallingIdentity(); |
| 5268 | try { |
| 5269 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5270 | TelephonyManager.class); |
| 5271 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5272 | if (subscriberId == null) { |
| 5273 | if (DBG) { |
| 5274 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 5275 | + subId); |
| 5276 | } |
| 5277 | return null; |
| 5278 | } |
| 5279 | |
| 5280 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5281 | .getSubscriptionInfo(subId); |
| 5282 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5283 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5284 | if (groupUuid == null) { |
| 5285 | return new String[]{subscriberId}; |
| 5286 | } |
| 5287 | |
| 5288 | // Get all subscriberIds from the group. |
| 5289 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5290 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
| 5291 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName()); |
| 5292 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5293 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5294 | if (subscriberId != null) { |
| 5295 | mergedSubscriberIds.add(subscriberId); |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5300 | } finally { |
| 5301 | Binder.restoreCallingIdentity(identity); |
| 5302 | |
| 5303 | } |
| 5304 | } |
| 5305 | |
| 5306 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5307 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5308 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5309 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5310 | |
| 5311 | final long identity = Binder.clearCallingIdentity(); |
| 5312 | try { |
| 5313 | final Phone phone = getPhone(subId); |
| 5314 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5315 | } finally { |
| 5316 | Binder.restoreCallingIdentity(identity); |
| 5317 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5318 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5319 | |
| 5320 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5321 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5322 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5323 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5324 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | |
| 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
| 5328 | final Phone phone = getPhone(subId); |
| 5329 | if (phone == null) { |
| 5330 | return false; |
| 5331 | } |
| 5332 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5333 | cdmaNonRoamingList); |
| 5334 | } finally { |
| 5335 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5336 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5340 | @Deprecated |
| 5341 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5342 | enforceModifyPermission(); |
| 5343 | |
| 5344 | int returnValue = 0; |
| 5345 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5346 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5347 | if(result.exception == null) { |
| 5348 | if (result.result != null) { |
| 5349 | byte[] responseData = (byte[])(result.result); |
| 5350 | if(responseData.length > oemResp.length) { |
| 5351 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5352 | responseData.length + "bytes. Buffer Size is " + |
| 5353 | oemResp.length + "bytes."); |
| 5354 | } |
| 5355 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5356 | returnValue = responseData.length; |
| 5357 | } |
| 5358 | } else { |
| 5359 | CommandException ex = (CommandException) result.exception; |
| 5360 | returnValue = ex.getCommandError().ordinal(); |
| 5361 | if(returnValue > 0) returnValue *= -1; |
| 5362 | } |
| 5363 | } catch (RuntimeException e) { |
| 5364 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5365 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5366 | if(returnValue > 0) returnValue *= -1; |
| 5367 | } |
| 5368 | |
| 5369 | return returnValue; |
| 5370 | } |
| 5371 | |
| 5372 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5373 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5374 | try { |
| 5375 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5376 | } catch (RuntimeException e) { |
| 5377 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5378 | } |
| 5379 | } |
| 5380 | |
| 5381 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5382 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5383 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5384 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5385 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5386 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5387 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5388 | final long identity = Binder.clearCallingIdentity(); |
| 5389 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5390 | TelephonyPermissions |
| 5391 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5392 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5393 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | } finally { |
| 5395 | Binder.restoreCallingIdentity(identity); |
| 5396 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5397 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5398 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5399 | |
| 5400 | @Override |
| 5401 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5402 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5403 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | |
| 5405 | final long identity = Binder.clearCallingIdentity(); |
| 5406 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5407 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5408 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | } finally { |
| 5410 | Binder.restoreCallingIdentity(identity); |
| 5411 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5415 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5416 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5417 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5418 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5419 | return false; |
| 5420 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | final long identity = Binder.clearCallingIdentity(); |
| 5423 | try { |
| 5424 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5425 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5426 | // In the long run, we may instead need to check if there exists a connection service |
| 5427 | // which can support video calling. |
| 5428 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5429 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5430 | return imsManager.isVtEnabledByPlatform() |
| 5431 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5432 | && imsManager.isVtEnabledByUser(); |
| 5433 | } finally { |
| 5434 | Binder.restoreCallingIdentity(identity); |
| 5435 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5436 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5437 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5438 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5439 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5440 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5441 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5442 | return false; |
| 5443 | } |
| 5444 | |
| 5445 | final long identity = Binder.clearCallingIdentity(); |
| 5446 | try { |
| 5447 | CarrierConfigManager configManager = |
| 5448 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5449 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5450 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5451 | } finally { |
| 5452 | Binder.restoreCallingIdentity(identity); |
| 5453 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5458 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5459 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5460 | return false; |
| 5461 | } |
| 5462 | |
| 5463 | final long identity = Binder.clearCallingIdentity(); |
| 5464 | try { |
| 5465 | CarrierConfigManager configManager = |
| 5466 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5467 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5469 | } finally { |
| 5470 | Binder.restoreCallingIdentity(identity); |
| 5471 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5472 | } |
| 5473 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5474 | @Override |
| 5475 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5476 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5477 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5478 | } |
| 5479 | |
| 5480 | @Override |
| 5481 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | final long identity = Binder.clearCallingIdentity(); |
| 5483 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5484 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 | } finally { |
| 5486 | Binder.restoreCallingIdentity(identity); |
| 5487 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5488 | } |
| 5489 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5490 | /** |
| 5491 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5492 | * support for the feature and device firmware support. |
| 5493 | * |
| 5494 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5495 | */ |
| 5496 | @Override |
| 5497 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5498 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5499 | final Phone phone = getPhone(subscriptionId); |
| 5500 | if (phone == null) { |
| 5501 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5502 | return false; |
| 5503 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5504 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5505 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5507 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5508 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5509 | return isCarrierSupported && isDeviceSupported; |
| 5510 | } finally { |
| 5511 | Binder.restoreCallingIdentity(identity); |
| 5512 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5513 | } |
| 5514 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5515 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5516 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5517 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5518 | * 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] | 5519 | */ |
| 5520 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | final long identity = Binder.clearCallingIdentity(); |
| 5522 | try { |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5523 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5524 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5525 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5526 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5527 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5528 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5529 | } finally { |
| 5530 | Binder.restoreCallingIdentity(identity); |
| 5531 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5532 | } |
| 5533 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5534 | /** |
| 5535 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5536 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5537 | * |
| 5538 | * <p>Requires Permission: |
| 5539 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5540 | */ |
| 5541 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5542 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5543 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5544 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5545 | return null; |
| 5546 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5547 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5548 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5549 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5550 | return null; |
| 5551 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5552 | |
| 5553 | final long identity = Binder.clearCallingIdentity(); |
| 5554 | try { |
| 5555 | return phone.getDeviceId(); |
| 5556 | } finally { |
| 5557 | Binder.restoreCallingIdentity(identity); |
| 5558 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5559 | } |
| 5560 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5561 | /** |
| 5562 | * {@hide} |
| 5563 | * Returns the IMS Registration Status on a particular subid |
| 5564 | * |
| 5565 | * @param subId |
| 5566 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5567 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5568 | Phone phone = getPhone(subId); |
| 5569 | if (phone != null) { |
| 5570 | return phone.isImsRegistered(); |
| 5571 | } else { |
| 5572 | return false; |
| 5573 | } |
| 5574 | } |
| 5575 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5576 | @Override |
| 5577 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
| 5580 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5581 | } finally { |
| 5582 | Binder.restoreCallingIdentity(identity); |
| 5583 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5584 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5585 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5586 | @Override |
| 5587 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5588 | final long identity = Binder.clearCallingIdentity(); |
| 5589 | try { |
| 5590 | Phone phone = getPhone(subscriptionId); |
| 5591 | if (phone == null) { |
| 5592 | return null; |
| 5593 | } |
| 5594 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5595 | } finally { |
| 5596 | Binder.restoreCallingIdentity(identity); |
| 5597 | } |
| 5598 | } |
| 5599 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5600 | /** |
| 5601 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5602 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5603 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | final long identity = Binder.clearCallingIdentity(); |
| 5605 | try { |
| 5606 | Phone phone = getPhone(subId); |
| 5607 | if (phone != null) { |
| 5608 | return phone.isWifiCallingEnabled(); |
| 5609 | } else { |
| 5610 | return false; |
| 5611 | } |
| 5612 | } finally { |
| 5613 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5614 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5615 | } |
| 5616 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5617 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5618 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5619 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5620 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | final long identity = Binder.clearCallingIdentity(); |
| 5622 | try { |
| 5623 | Phone phone = getPhone(subId); |
| 5624 | if (phone != null) { |
| 5625 | return phone.isVideoEnabled(); |
| 5626 | } else { |
| 5627 | return false; |
| 5628 | } |
| 5629 | } finally { |
| 5630 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | /** |
| 5635 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5636 | * defined in {@link ImsRegistrationImplBase}. |
| 5637 | */ |
| 5638 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | final long identity = Binder.clearCallingIdentity(); |
| 5640 | try { |
| 5641 | Phone phone = getPhone(subId); |
| 5642 | if (phone != null) { |
| 5643 | return phone.getImsRegistrationTech(); |
| 5644 | } else { |
| 5645 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5646 | } |
| 5647 | } finally { |
| 5648 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5649 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5650 | } |
| 5651 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5652 | @Override |
| 5653 | public void factoryReset(int subId) { |
| 5654 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5655 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5656 | return; |
| 5657 | } |
| 5658 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5659 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5660 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5661 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5662 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5663 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5664 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5665 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5666 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5667 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5668 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5669 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5670 | // There has been issues when Sms raw table somehow stores orphan |
| 5671 | // fragments. They lead to garbled message when new fragments come |
| 5672 | // in and combined with those stale ones. In case this happens again, |
| 5673 | // user can reset all network settings which will clean up this table. |
| 5674 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5675 | } finally { |
| 5676 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5677 | } |
| 5678 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5679 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5680 | private void cleanUpSmsRawTable(Context context) { |
| 5681 | ContentResolver resolver = context.getContentResolver(); |
| 5682 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5683 | resolver.delete(uri, null, null); |
| 5684 | } |
| 5685 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5686 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5687 | public String getSimLocaleForSubscriber(int subId) { |
| 5688 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5689 | final Phone phone = getPhone(subId); |
| 5690 | if (phone == null) { |
| 5691 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5692 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5693 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | final long identity = Binder.clearCallingIdentity(); |
| 5695 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5696 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5697 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5698 | if (info == null) { |
| 5699 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5700 | return null; |
| 5701 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5703 | // preferences (EF-PL and EF-LI)... |
| 5704 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5706 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5707 | if (localeFromDefaultSim != null) { |
| 5708 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5709 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5710 | + localeFromDefaultSim); |
| 5711 | return localeFromDefaultSim.toLanguageTag(); |
| 5712 | } else { |
| 5713 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5714 | } |
| 5715 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5716 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5717 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5718 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5719 | // the SIM and carrier preferences does not include a country we add the country |
| 5720 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5721 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5722 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5723 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5724 | return mccLocale.toLanguageTag(); |
| 5725 | } |
| 5726 | |
| 5727 | if (DBG) log("No locale found - returning null"); |
| 5728 | return null; |
| 5729 | } finally { |
| 5730 | Binder.restoreCallingIdentity(identity); |
| 5731 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5732 | } |
| 5733 | |
| 5734 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5735 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5736 | } |
| 5737 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5738 | /** |
| 5739 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5740 | */ |
| 5741 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5742 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5743 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5744 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5745 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5746 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5747 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5748 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5749 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5750 | * representing the state of the modem. |
| 5751 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5752 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5753 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5754 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5755 | */ |
| 5756 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5757 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5758 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5759 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5760 | |
| 5761 | final long identity = Binder.clearCallingIdentity(); |
| 5762 | try { |
| 5763 | ModemActivityInfo ret = null; |
| 5764 | synchronized (mLastModemActivityInfo) { |
| 5765 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5766 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5767 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5768 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5770 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 5771 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5772 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5773 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | } |
| 5775 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5776 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5777 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5778 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5779 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5780 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 5781 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 5782 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 5783 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5784 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5787 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5788 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5789 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 5790 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5791 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5792 | Bundle bundle = new Bundle(); |
| 5793 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5794 | result.send(0, bundle); |
| 5795 | } finally { |
| 5796 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5797 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5798 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5799 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5800 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5801 | // less than total activity duration. |
| 5802 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5803 | if (info == null) { |
| 5804 | return false; |
| 5805 | } |
| 5806 | int activityDurationMs = |
| 5807 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5808 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5809 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 5810 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 5811 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5812 | } |
| 5813 | return (info.isValid() |
| 5814 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5815 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 5816 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5817 | && (totalTxTimeMs <= activityDurationMs)); |
| 5818 | } |
| 5819 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5820 | /** |
| 5821 | * {@hide} |
| 5822 | * Returns the service state information on specified subscription. |
| 5823 | */ |
| 5824 | @Override |
| 5825 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5826 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5827 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5828 | return null; |
| 5829 | } |
| 5830 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5831 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5832 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5833 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5834 | .setCallingPackage(callingPackage) |
| 5835 | .setCallingPid(Binder.getCallingPid()) |
| 5836 | .setCallingUid(Binder.getCallingUid()) |
| 5837 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5838 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5839 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5840 | .build()); |
| 5841 | |
| 5842 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5843 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5844 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5845 | .setCallingPackage(callingPackage) |
| 5846 | .setCallingPid(Binder.getCallingPid()) |
| 5847 | .setCallingUid(Binder.getCallingUid()) |
| 5848 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5849 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5850 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5851 | .build()); |
| 5852 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5853 | boolean hasFinePermission = |
| 5854 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5855 | boolean hasCoarsePermission = |
| 5856 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5857 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5858 | final long identity = Binder.clearCallingIdentity(); |
| 5859 | try { |
| 5860 | final Phone phone = getPhone(subId); |
| 5861 | if (phone == null) { |
| 5862 | return null; |
| 5863 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5864 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5865 | ServiceState ss = phone.getServiceState(); |
| 5866 | |
| 5867 | // Scrub out the location info in ServiceState depending on what level of access |
| 5868 | // the caller has. |
| 5869 | if (hasFinePermission) return ss; |
| 5870 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5871 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5872 | } finally { |
| 5873 | Binder.restoreCallingIdentity(identity); |
| 5874 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5875 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5876 | |
| 5877 | /** |
| 5878 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5879 | * |
| 5880 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5881 | * voicemail ringtone. |
| 5882 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5883 | * PhoneAccount. |
| 5884 | */ |
| 5885 | @Override |
| 5886 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5887 | final long identity = Binder.clearCallingIdentity(); |
| 5888 | try { |
| 5889 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5890 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5891 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5892 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5893 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5895 | } finally { |
| 5896 | Binder.restoreCallingIdentity(identity); |
| 5897 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5901 | * Sets the per-account voicemail ringtone. |
| 5902 | * |
| 5903 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5904 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5905 | * |
| 5906 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5907 | * voicemail ringtone. |
| 5908 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5909 | * PhoneAccount. |
| 5910 | */ |
| 5911 | @Override |
| 5912 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5913 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5914 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5915 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5916 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5917 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5919 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5920 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5921 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5922 | |
| 5923 | final long identity = Binder.clearCallingIdentity(); |
| 5924 | try { |
| 5925 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5926 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5927 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5928 | } |
| 5929 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5930 | } finally { |
| 5931 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5932 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5933 | } |
| 5934 | |
| 5935 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5936 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5937 | * |
| 5938 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5939 | * voicemail vibration setting. |
| 5940 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5941 | */ |
| 5942 | @Override |
| 5943 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5944 | final long identity = Binder.clearCallingIdentity(); |
| 5945 | try { |
| 5946 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5947 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5948 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5950 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5951 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5952 | } finally { |
| 5953 | Binder.restoreCallingIdentity(identity); |
| 5954 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5955 | } |
| 5956 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5957 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5958 | * Sets the per-account voicemail vibration. |
| 5959 | * |
| 5960 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5961 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5962 | * |
| 5963 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5964 | * voicemail vibration setting. |
| 5965 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5966 | * specific PhoneAccount. |
| 5967 | */ |
| 5968 | @Override |
| 5969 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5970 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5971 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5972 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5973 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5974 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5976 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5977 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5978 | } |
| 5979 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5980 | final long identity = Binder.clearCallingIdentity(); |
| 5981 | try { |
| 5982 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5983 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5984 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5985 | } |
| 5986 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5987 | } finally { |
| 5988 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5989 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5993 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5994 | * |
| 5995 | * @throws SecurityException if the caller does not have the required permission |
| 5996 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5997 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5998 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5999 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6000 | } |
| 6001 | |
| 6002 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6003 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6004 | * permission. |
| 6005 | * |
| 6006 | * @throws SecurityException if the caller does not have the required permission |
| 6007 | */ |
| 6008 | private void enforceSendSmsPermission() { |
| 6009 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6010 | } |
| 6011 | |
| 6012 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6013 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6014 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6015 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6016 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6017 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6018 | final long identity = Binder.clearCallingIdentity(); |
| 6019 | try { |
| 6020 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6021 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6022 | if (componentName == null) { |
| 6023 | throw new SecurityException( |
| 6024 | "Caller not current active visual voicemail package[null]"); |
| 6025 | } |
| 6026 | String vvmPackage = componentName.getPackageName(); |
| 6027 | if (!callingPackage.equals(vvmPackage)) { |
| 6028 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6029 | + vvmPackage + "]"); |
| 6030 | } |
| 6031 | } finally { |
| 6032 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6033 | } |
| 6034 | } |
| 6035 | |
| 6036 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6037 | * Return the application ID for the app type. |
| 6038 | * |
| 6039 | * @param subId the subscription ID that this request applies to. |
| 6040 | * @param appType the uicc app type. |
| 6041 | * @return Application ID for specificied app type, or null if no uicc. |
| 6042 | */ |
| 6043 | @Override |
| 6044 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6045 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6046 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6047 | |
| 6048 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6049 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | if (phone == null) { |
| 6051 | return null; |
| 6052 | } |
| 6053 | String aid = null; |
| 6054 | try { |
| 6055 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6056 | .getApplicationByType(appType).getAid(); |
| 6057 | } catch (Exception e) { |
| 6058 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6059 | } |
| 6060 | return aid; |
| 6061 | } finally { |
| 6062 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6063 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6064 | } |
| 6065 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6066 | /** |
| 6067 | * Return the Electronic Serial Number. |
| 6068 | * |
| 6069 | * @param subId the subscription ID that this request applies to. |
| 6070 | * @return ESN or null if error. |
| 6071 | */ |
| 6072 | @Override |
| 6073 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6074 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6075 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6076 | |
| 6077 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6078 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6079 | if (phone == null) { |
| 6080 | return null; |
| 6081 | } |
| 6082 | String esn = null; |
| 6083 | try { |
| 6084 | esn = phone.getEsn(); |
| 6085 | } catch (Exception e) { |
| 6086 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6087 | } |
| 6088 | return esn; |
| 6089 | } finally { |
| 6090 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6091 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6092 | } |
| 6093 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6094 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6095 | * Return the Preferred Roaming List Version. |
| 6096 | * |
| 6097 | * @param subId the subscription ID that this request applies to. |
| 6098 | * @return PRLVersion or null if error. |
| 6099 | */ |
| 6100 | @Override |
| 6101 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6102 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6103 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6104 | |
| 6105 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6106 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | if (phone == null) { |
| 6108 | return null; |
| 6109 | } |
| 6110 | String cdmaPrlVersion = null; |
| 6111 | try { |
| 6112 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6113 | } catch (Exception e) { |
| 6114 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6115 | } |
| 6116 | return cdmaPrlVersion; |
| 6117 | } finally { |
| 6118 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6119 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6120 | } |
| 6121 | |
| 6122 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6123 | * Get snapshot of Telephony histograms |
| 6124 | * @return List of Telephony histograms |
| 6125 | * @hide |
| 6126 | */ |
| 6127 | @Override |
| 6128 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6130 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6131 | |
| 6132 | final long identity = Binder.clearCallingIdentity(); |
| 6133 | try { |
| 6134 | return RIL.getTelephonyRILTimingHistograms(); |
| 6135 | } finally { |
| 6136 | Binder.restoreCallingIdentity(identity); |
| 6137 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6138 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6139 | |
| 6140 | /** |
| 6141 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6142 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6143 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6144 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6145 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6146 | * @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] | 6147 | */ |
| 6148 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6149 | @TelephonyManager.SetCarrierRestrictionResult |
| 6150 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6151 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6152 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6153 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6154 | if (carrierRestrictionRules == null) { |
| 6155 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6156 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6157 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | final long identity = Binder.clearCallingIdentity(); |
| 6159 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6160 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6161 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6162 | } finally { |
| 6163 | Binder.restoreCallingIdentity(identity); |
| 6164 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | /** |
| 6168 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6169 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6170 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6171 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6172 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6173 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6174 | */ |
| 6175 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6176 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6177 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6178 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6179 | |
| 6180 | final long identity = Binder.clearCallingIdentity(); |
| 6181 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6182 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6183 | if (response instanceof CarrierRestrictionRules) { |
| 6184 | return (CarrierRestrictionRules) response; |
| 6185 | } |
| 6186 | // Response is an Exception of some kind, |
| 6187 | // which is signalled to the user as a NULL retval |
| 6188 | return null; |
| 6189 | } catch (Exception e) { |
| 6190 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6191 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6192 | } finally { |
| 6193 | Binder.restoreCallingIdentity(identity); |
| 6194 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6195 | } |
| 6196 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6197 | /** |
| 6198 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6199 | * @param subId the subscription ID that this action applies to. |
| 6200 | * @param enabled control enable or disable metered apns. |
| 6201 | * {@hide} |
| 6202 | */ |
| 6203 | @Override |
| 6204 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6205 | enforceModifyPermission(); |
| 6206 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6207 | |
| 6208 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6209 | if (phone == null) { |
| 6210 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6211 | return; |
| 6212 | } |
| 6213 | try { |
| 6214 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6215 | } catch (Exception e) { |
| 6216 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6217 | } finally { |
| 6218 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | /** |
| 6223 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6224 | * @param subId the subscription ID that this action applies to. |
| 6225 | * @param enabled control enable or disable radio. |
| 6226 | * {@hide} |
| 6227 | */ |
| 6228 | @Override |
| 6229 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6230 | enforceModifyPermission(); |
| 6231 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6232 | |
| 6233 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6234 | if (phone == null) { |
| 6235 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6236 | return; |
| 6237 | } |
| 6238 | try { |
| 6239 | phone.carrierActionSetRadioEnabled(enabled); |
| 6240 | } catch (Exception e) { |
| 6241 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | } finally { |
| 6243 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6244 | } |
| 6245 | } |
| 6246 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6247 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6248 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6249 | * network status based on which carrier apps could apply actions accordingly, |
| 6250 | * enable/disable default url handler for example. |
| 6251 | * |
| 6252 | * @param subId the subscription ID that this action applies to. |
| 6253 | * @param report control start/stop reporting the default network status. |
| 6254 | * {@hide} |
| 6255 | */ |
| 6256 | @Override |
| 6257 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6258 | enforceModifyPermission(); |
| 6259 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6260 | |
| 6261 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6262 | if (phone == null) { |
| 6263 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6264 | return; |
| 6265 | } |
| 6266 | try { |
| 6267 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6268 | } catch (Exception e) { |
| 6269 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | } finally { |
| 6271 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6276 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6277 | * @param subId the subscription ID that this action applies to. |
| 6278 | * {@hide} |
| 6279 | */ |
| 6280 | @Override |
| 6281 | public void carrierActionResetAll(int subId) { |
| 6282 | enforceModifyPermission(); |
| 6283 | final Phone phone = getPhone(subId); |
| 6284 | if (phone == null) { |
| 6285 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6286 | return; |
| 6287 | } |
| 6288 | try { |
| 6289 | phone.carrierActionResetAll(); |
| 6290 | } catch (Exception e) { |
| 6291 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6292 | } |
| 6293 | } |
| 6294 | |
| 6295 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6296 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6297 | * bug report is being generated. |
| 6298 | */ |
| 6299 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6300 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6301 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6302 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6303 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6304 | + Binder.getCallingPid() |
| 6305 | + ", uid=" + Binder.getCallingUid() |
| 6306 | + "without permission " |
| 6307 | + android.Manifest.permission.DUMP); |
| 6308 | return; |
| 6309 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6310 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6311 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6312 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6313 | @Override |
| 6314 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6315 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6316 | throws RemoteException { |
| 6317 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6318 | } |
| 6319 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6320 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6321 | * Get aggregated video call data usage since boot. |
| 6322 | * |
| 6323 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6324 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6325 | * {@hide} |
| 6326 | */ |
| 6327 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6328 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6329 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6330 | null); |
| 6331 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6332 | final long identity = Binder.clearCallingIdentity(); |
| 6333 | try { |
| 6334 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6335 | // records the delta with the corresponding network identity. |
| 6336 | // We just return the total video call data usage snapshot since boot. |
| 6337 | Phone phone = getPhone(subId); |
| 6338 | if (phone != null) { |
| 6339 | return phone.getVtDataUsage(perUidStats); |
| 6340 | } |
| 6341 | return null; |
| 6342 | } finally { |
| 6343 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6344 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6345 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6346 | |
| 6347 | /** |
| 6348 | * Policy control of data connection. Usually used when data limit is passed. |
| 6349 | * @param enabled True if enabling the data, otherwise disabling. |
| 6350 | * @param subId Subscription index |
| 6351 | * {@hide} |
| 6352 | */ |
| 6353 | @Override |
| 6354 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6355 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6356 | |
| 6357 | final long identity = Binder.clearCallingIdentity(); |
| 6358 | try { |
| 6359 | Phone phone = getPhone(subId); |
| 6360 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6361 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6362 | } |
| 6363 | } finally { |
| 6364 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6365 | } |
| 6366 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6367 | |
| 6368 | /** |
| 6369 | * Get Client request stats |
| 6370 | * @return List of Client Request Stats |
| 6371 | * @hide |
| 6372 | */ |
| 6373 | @Override |
| 6374 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6375 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6376 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6377 | return null; |
| 6378 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6379 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6380 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6381 | final long identity = Binder.clearCallingIdentity(); |
| 6382 | try { |
| 6383 | if (phone != null) { |
| 6384 | return phone.getClientRequestStats(); |
| 6385 | } |
| 6386 | |
| 6387 | return null; |
| 6388 | } finally { |
| 6389 | Binder.restoreCallingIdentity(identity); |
| 6390 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6391 | } |
| 6392 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6393 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6394 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6395 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6396 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6397 | |
| 6398 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6399 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6400 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6401 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6402 | * @param state State of SIM (power down, power up, pass through) |
| 6403 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6404 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6405 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6406 | * |
| 6407 | **/ |
| 6408 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6409 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6410 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6411 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6412 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6413 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6414 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | final long identity = Binder.clearCallingIdentity(); |
| 6416 | try { |
| 6417 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6418 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6419 | } |
| 6420 | } finally { |
| 6421 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6422 | } |
| 6423 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6424 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6425 | private boolean isUssdApiAllowed(int subId) { |
| 6426 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6427 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6428 | if (configManager == null) { |
| 6429 | return false; |
| 6430 | } |
| 6431 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6432 | if (pb == null) { |
| 6433 | return false; |
| 6434 | } |
| 6435 | return pb.getBoolean( |
| 6436 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6437 | } |
| 6438 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6439 | /** |
| 6440 | * Check if phone is in emergency callback mode |
| 6441 | * @return true if phone is in emergency callback mode |
| 6442 | * @param subId sub id |
| 6443 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6444 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6445 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6446 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6447 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6448 | |
| 6449 | final long identity = Binder.clearCallingIdentity(); |
| 6450 | try { |
| 6451 | if (phone != null) { |
| 6452 | return phone.isInEcm(); |
| 6453 | } else { |
| 6454 | return false; |
| 6455 | } |
| 6456 | } finally { |
| 6457 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6458 | } |
| 6459 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6460 | |
| 6461 | /** |
| 6462 | * Get the current signal strength information for the given subscription. |
| 6463 | * Because this information is not updated when the device is in a low power state |
| 6464 | * it should not be relied-upon to be current. |
| 6465 | * @param subId Subscription index |
| 6466 | * @return the most recent cached signal strength info from the modem |
| 6467 | */ |
| 6468 | @Override |
| 6469 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6470 | final long identity = Binder.clearCallingIdentity(); |
| 6471 | try { |
| 6472 | Phone p = getPhone(subId); |
| 6473 | if (p == null) { |
| 6474 | return null; |
| 6475 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6477 | return p.getSignalStrength(); |
| 6478 | } finally { |
| 6479 | Binder.restoreCallingIdentity(identity); |
| 6480 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6481 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6482 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6483 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6484 | * Get the current modem radio state for the given slot. |
| 6485 | * @param slotIndex slot index. |
| 6486 | * @param callingPackage the name of the package making the call. |
| 6487 | * @return the current radio power state from the modem |
| 6488 | */ |
| 6489 | @Override |
| 6490 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6491 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6492 | if (phone != null) { |
| 6493 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6494 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6495 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6496 | } |
| 6497 | |
| 6498 | final long identity = Binder.clearCallingIdentity(); |
| 6499 | try { |
| 6500 | return phone.getRadioPowerState(); |
| 6501 | } finally { |
| 6502 | Binder.restoreCallingIdentity(identity); |
| 6503 | } |
| 6504 | } |
| 6505 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6506 | } |
| 6507 | |
| 6508 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6509 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6510 | * |
| 6511 | * <p>Requires one of the following permissions: |
| 6512 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6513 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6514 | * privileges. |
| 6515 | * |
| 6516 | * @param subId subscription id |
| 6517 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6518 | * {@code false}. |
| 6519 | */ |
| 6520 | @Override |
| 6521 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6522 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6523 | null /* message */); |
| 6524 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6525 | boolean isEnabled = false; |
| 6526 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6527 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6528 | Phone phone = getPhone(subId); |
| 6529 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6530 | } catch (Exception e) { |
| 6531 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6532 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6533 | } finally { |
| 6534 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6535 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6536 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | |
| 6540 | /** |
| 6541 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6542 | * |
| 6543 | * <p> Requires permission: |
| 6544 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6545 | * privileges. |
| 6546 | * |
| 6547 | * @param subId subscription id |
| 6548 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6549 | */ |
| 6550 | @Override |
| 6551 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6553 | mApp, subId, "setDataRoamingEnabled"); |
| 6554 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6555 | final long identity = Binder.clearCallingIdentity(); |
| 6556 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6557 | Phone phone = getPhone(subId); |
| 6558 | if (phone != null) { |
| 6559 | phone.setDataRoamingEnabled(isEnabled); |
| 6560 | } |
| 6561 | } finally { |
| 6562 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6563 | } |
| 6564 | } |
| 6565 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6566 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6567 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6568 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6569 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6570 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6571 | boolean isAllowed = true; |
| 6572 | final long identity = Binder.clearCallingIdentity(); |
| 6573 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6574 | Phone phone = getPhone(subId); |
| 6575 | if (phone != null) { |
| 6576 | isAllowed = phone.isCspPlmnEnabled(); |
| 6577 | } |
| 6578 | } finally { |
| 6579 | Binder.restoreCallingIdentity(identity); |
| 6580 | } |
| 6581 | return isAllowed; |
| 6582 | } |
| 6583 | |
| 6584 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6585 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6586 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6587 | try { |
| 6588 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6589 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6590 | } catch (SecurityException e) { |
| 6591 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6592 | // has carrier privileges on an active UICC |
| 6593 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6594 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6595 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6596 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6597 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6598 | |
| 6599 | final long identity = Binder.clearCallingIdentity(); |
| 6600 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6601 | UiccController uiccController = UiccController.getInstance(); |
| 6602 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6603 | if (hasReadPermission) { |
| 6604 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6605 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6606 | |
| 6607 | // Remove private info if the caller doesn't have access |
| 6608 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6609 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6610 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6611 | // is available |
| 6612 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6613 | if (card == null || card.getUiccProfile() == null) { |
| 6614 | // assume no access if the card or profile is unavailable |
| 6615 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6616 | continue; |
| 6617 | } |
| 6618 | UiccProfile profile = card.getUiccProfile(); |
| 6619 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6620 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6621 | filteredInfos.add(cardInfo); |
| 6622 | } else { |
| 6623 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6624 | } |
| 6625 | } |
| 6626 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6627 | } finally { |
| 6628 | Binder.restoreCallingIdentity(identity); |
| 6629 | } |
| 6630 | } |
| 6631 | |
| 6632 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6633 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6634 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | final long identity = Binder.clearCallingIdentity(); |
| 6637 | try { |
| 6638 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6639 | if (slots == null) { |
| 6640 | Rlog.i(LOG_TAG, "slots is null."); |
| 6641 | return null; |
| 6642 | } |
| 6643 | |
| 6644 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6645 | for (int i = 0; i < slots.length; i++) { |
| 6646 | UiccSlot slot = slots[i]; |
| 6647 | if (slot == null) { |
| 6648 | continue; |
| 6649 | } |
| 6650 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6651 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6652 | UiccCard card = slot.getUiccCard(); |
| 6653 | if (card != null) { |
| 6654 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6655 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 6656 | cardId = slot.getEid(); |
| 6657 | if (TextUtils.isEmpty(cardId)) { |
| 6658 | cardId = slot.getIccId(); |
| 6659 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6660 | } |
| 6661 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 6662 | if (cardId != null) { |
| 6663 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 6664 | // if cardId is an EID, it's all digits so this is fine |
| 6665 | cardId = IccUtils.stripTrailingFs(cardId); |
| 6666 | } |
| 6667 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6668 | int cardState = 0; |
| 6669 | switch (slot.getCardState()) { |
| 6670 | case CARDSTATE_ABSENT: |
| 6671 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6672 | break; |
| 6673 | case CARDSTATE_PRESENT: |
| 6674 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6675 | break; |
| 6676 | case CARDSTATE_ERROR: |
| 6677 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6678 | break; |
| 6679 | case CARDSTATE_RESTRICTED: |
| 6680 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6681 | break; |
| 6682 | default: |
| 6683 | break; |
| 6684 | |
| 6685 | } |
| 6686 | |
| 6687 | infos[i] = new UiccSlotInfo( |
| 6688 | slot.isActive(), |
| 6689 | slot.isEuicc(), |
| 6690 | cardId, |
| 6691 | cardState, |
| 6692 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6693 | slot.isExtendedApduSupported(), |
| 6694 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6695 | } |
| 6696 | return infos; |
| 6697 | } finally { |
| 6698 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6699 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6700 | } |
| 6701 | |
| 6702 | @Override |
| 6703 | public boolean switchSlots(int[] physicalSlots) { |
| 6704 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | |
| 6706 | final long identity = Binder.clearCallingIdentity(); |
| 6707 | try { |
| 6708 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6709 | } finally { |
| 6710 | Binder.restoreCallingIdentity(identity); |
| 6711 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6712 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6713 | |
| 6714 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6715 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6716 | final long identity = Binder.clearCallingIdentity(); |
| 6717 | try { |
| 6718 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6719 | } finally { |
| 6720 | Binder.restoreCallingIdentity(identity); |
| 6721 | } |
| 6722 | } |
| 6723 | |
| 6724 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6725 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6726 | enforceModifyPermission(); |
| 6727 | final Phone phone = getPhone(subId); |
| 6728 | if (phone == null) { |
| 6729 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6730 | return; |
| 6731 | } |
| 6732 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
| 6735 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6736 | } finally { |
| 6737 | Binder.restoreCallingIdentity(identity); |
| 6738 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6739 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6740 | |
| 6741 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6742 | * A test API to reload the UICC profile. |
| 6743 | * |
| 6744 | * <p>Requires that the calling app has permission |
| 6745 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6746 | * @hide |
| 6747 | */ |
| 6748 | @Override |
| 6749 | public void refreshUiccProfile(int subId) { |
| 6750 | enforceModifyPermission(); |
| 6751 | |
| 6752 | final long identity = Binder.clearCallingIdentity(); |
| 6753 | try { |
| 6754 | Phone phone = getPhone(subId); |
| 6755 | if (phone == null) { |
| 6756 | return; |
| 6757 | } |
| 6758 | UiccCard uiccCard = phone.getUiccCard(); |
| 6759 | if (uiccCard == null) { |
| 6760 | return; |
| 6761 | } |
| 6762 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6763 | if (uiccProfile == null) { |
| 6764 | return; |
| 6765 | } |
| 6766 | uiccProfile.refresh(); |
| 6767 | } finally { |
| 6768 | Binder.restoreCallingIdentity(identity); |
| 6769 | } |
| 6770 | } |
| 6771 | |
| 6772 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6773 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6774 | */ |
| 6775 | private boolean getDefaultDataEnabled() { |
| 6776 | return "true".equalsIgnoreCase( |
| 6777 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6778 | } |
| 6779 | |
| 6780 | /** |
| 6781 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6782 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6783 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6784 | */ |
| 6785 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6786 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6787 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6788 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6789 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6790 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6791 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6792 | return isDataRoamingEnabled; |
| 6793 | } |
| 6794 | |
| 6795 | /** |
| 6796 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6797 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6798 | */ |
| 6799 | private int getDefaultNetworkType(int subId) { |
| 6800 | return Integer.parseInt( |
| 6801 | TelephonyManager.getTelephonyProperty( |
| 6802 | mSubscriptionController.getPhoneId(subId), |
| 6803 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6804 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6805 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6806 | |
| 6807 | @Override |
| 6808 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6809 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6810 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6811 | |
| 6812 | final long identity = Binder.clearCallingIdentity(); |
| 6813 | try { |
| 6814 | final Phone phone = getPhone(subId); |
| 6815 | if (phone == null) { |
| 6816 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6817 | return; |
| 6818 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6819 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6820 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6821 | } finally { |
| 6822 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6823 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | @Override |
| 6827 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6828 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6829 | |
| 6830 | final long identity = Binder.clearCallingIdentity(); |
| 6831 | try { |
| 6832 | final Phone phone = getPhone(subId); |
| 6833 | if (phone == null) { |
| 6834 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6835 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6836 | } |
| 6837 | return phone.getCarrierIdListVersion(); |
| 6838 | } finally { |
| 6839 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6840 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6841 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6842 | |
| 6843 | @Override |
| 6844 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6845 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6846 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6847 | return -1; |
| 6848 | } |
| 6849 | |
| 6850 | final long identity = Binder.clearCallingIdentity(); |
| 6851 | try { |
| 6852 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6853 | } finally { |
| 6854 | Binder.restoreCallingIdentity(identity); |
| 6855 | } |
| 6856 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6857 | |
| 6858 | @Override |
| 6859 | public int getCdmaRoamingMode(int subId) { |
| 6860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6861 | mApp, subId, "getCdmaRoamingMode"); |
| 6862 | |
| 6863 | final long identity = Binder.clearCallingIdentity(); |
| 6864 | try { |
| 6865 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6866 | } finally { |
| 6867 | Binder.restoreCallingIdentity(identity); |
| 6868 | } |
| 6869 | } |
| 6870 | |
| 6871 | @Override |
| 6872 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6874 | mApp, subId, "setCdmaRoamingMode"); |
| 6875 | |
| 6876 | final long identity = Binder.clearCallingIdentity(); |
| 6877 | try { |
| 6878 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6879 | } finally { |
| 6880 | Binder.restoreCallingIdentity(identity); |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | @Override |
| 6885 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6887 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6888 | |
| 6889 | final long identity = Binder.clearCallingIdentity(); |
| 6890 | try { |
| 6891 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6892 | } finally { |
| 6893 | Binder.restoreCallingIdentity(identity); |
| 6894 | } |
| 6895 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6896 | |
| 6897 | private void ensureUserRunning(int userId) { |
| 6898 | if (!mUserManager.isUserRunning(userId)) { |
| 6899 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6900 | } |
| 6901 | } |
| 6902 | |
| 6903 | /** |
| 6904 | * Returns a list of SMS apps on a given user. |
| 6905 | * |
| 6906 | * Only the shell user (UID 2000 or 0) can call it. |
| 6907 | * Target user must be running. |
| 6908 | */ |
| 6909 | @Override |
| 6910 | public String[] getSmsApps(int userId) { |
| 6911 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6912 | ensureUserRunning(userId); |
| 6913 | |
| 6914 | final Collection<SmsApplicationData> apps = |
| 6915 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6916 | |
| 6917 | String[] ret = new String[apps.size()]; |
| 6918 | int i = 0; |
| 6919 | for (SmsApplicationData app : apps) { |
| 6920 | ret[i++] = app.mPackageName; |
| 6921 | } |
| 6922 | return ret; |
| 6923 | } |
| 6924 | |
| 6925 | /** |
| 6926 | * Returns the default SMS app package name on a given user. |
| 6927 | * |
| 6928 | * Only the shell user (UID 2000 or 0) can call it. |
| 6929 | * Target user must be running. |
| 6930 | */ |
| 6931 | @Override |
| 6932 | public String getDefaultSmsApp(int userId) { |
| 6933 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6934 | ensureUserRunning(userId); |
| 6935 | |
| 6936 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6937 | /* updateIfNeeded= */ true, userId); |
| 6938 | return cn == null ? null : cn.getPackageName(); |
| 6939 | } |
| 6940 | |
| 6941 | /** |
| 6942 | * Set a package as the default SMS app on a given user. |
| 6943 | * |
| 6944 | * Only the shell user (UID 2000 or 0) can call it. |
| 6945 | * Target user must be running. |
| 6946 | */ |
| 6947 | @Override |
| 6948 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6949 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6950 | ensureUserRunning(userId); |
| 6951 | |
| 6952 | boolean found = false; |
| 6953 | for (String pkg : getSmsApps(userId)) { |
| 6954 | if (TextUtils.equals(packageName, pkg)) { |
| 6955 | found = true; |
| 6956 | break; |
| 6957 | } |
| 6958 | } |
| 6959 | if (!found) { |
| 6960 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6961 | } |
| 6962 | |
| 6963 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6964 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6965 | |
| 6966 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6967 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6968 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6969 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6970 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6971 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6972 | } |
| 6973 | final long identity = Binder.clearCallingIdentity(); |
| 6974 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6975 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6976 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6977 | if (phone.getEmergencyNumberTracker() != null |
| 6978 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6979 | emergencyNumberListInternal.put( |
| 6980 | phone.getSubId(), |
| 6981 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6982 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6983 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6984 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6985 | } finally { |
| 6986 | Binder.restoreCallingIdentity(identity); |
| 6987 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6988 | } |
| 6989 | |
| 6990 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6991 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6992 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6993 | if (!exactMatch) { |
| 6994 | TelephonyPermissions |
| 6995 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6996 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6997 | } |
| 6998 | final long identity = Binder.clearCallingIdentity(); |
| 6999 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7000 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7001 | if (phone.getEmergencyNumberTracker() != null |
| 7002 | && phone.getEmergencyNumberTracker() != null) { |
| 7003 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7004 | number, exactMatch)) { |
| 7005 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7006 | } |
| 7007 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7008 | } |
| 7009 | return false; |
| 7010 | } finally { |
| 7011 | Binder.restoreCallingIdentity(identity); |
| 7012 | } |
| 7013 | } |
| 7014 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7015 | /** |
| 7016 | * Update emergency number list for test mode. |
| 7017 | */ |
| 7018 | @Override |
| 7019 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7020 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7021 | "updateEmergencyNumberListTestMode"); |
| 7022 | |
| 7023 | final long identity = Binder.clearCallingIdentity(); |
| 7024 | try { |
| 7025 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7026 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7027 | if (tracker != null) { |
| 7028 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7029 | } |
| 7030 | } |
| 7031 | } finally { |
| 7032 | Binder.restoreCallingIdentity(identity); |
| 7033 | } |
| 7034 | } |
| 7035 | |
| 7036 | /** |
| 7037 | * Get the full emergency number list for test mode. |
| 7038 | */ |
| 7039 | @Override |
| 7040 | public List<String> getEmergencyNumberListTestMode() { |
| 7041 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7042 | "getEmergencyNumberListTestMode"); |
| 7043 | |
| 7044 | final long identity = Binder.clearCallingIdentity(); |
| 7045 | try { |
| 7046 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7047 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7048 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7049 | if (tracker != null) { |
| 7050 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7051 | emergencyNumbers.add(num.getNumber()); |
| 7052 | } |
| 7053 | } |
| 7054 | } |
| 7055 | return new ArrayList<>(emergencyNumbers); |
| 7056 | } finally { |
| 7057 | Binder.restoreCallingIdentity(identity); |
| 7058 | } |
| 7059 | } |
| 7060 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7061 | @Override |
| 7062 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7063 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7064 | Phone phone = getPhone(subId); |
| 7065 | if (phone == null) { |
| 7066 | return null; |
| 7067 | } |
| 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
| 7070 | UiccProfile profile = UiccController.getInstance() |
| 7071 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7072 | if (profile != null) { |
| 7073 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7074 | } |
| 7075 | } finally { |
| 7076 | Binder.restoreCallingIdentity(identity); |
| 7077 | } |
| 7078 | return null; |
| 7079 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7080 | |
| 7081 | /** |
| 7082 | * Enable or disable a modem stack. |
| 7083 | */ |
| 7084 | @Override |
| 7085 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7086 | enforceModifyPermission(); |
| 7087 | |
| 7088 | final long identity = Binder.clearCallingIdentity(); |
| 7089 | try { |
| 7090 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7091 | if (phone == null) { |
| 7092 | return false; |
| 7093 | } else { |
| 7094 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7095 | } |
| 7096 | } finally { |
| 7097 | Binder.restoreCallingIdentity(identity); |
| 7098 | } |
| 7099 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7100 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7101 | /** |
| 7102 | * Whether a modem stack is enabled or not. |
| 7103 | */ |
| 7104 | @Override |
| 7105 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 7106 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7107 | if (phone == null) return false; |
| 7108 | |
| 7109 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7110 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 7111 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7112 | } |
| 7113 | |
| 7114 | final long identity = Binder.clearCallingIdentity(); |
| 7115 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7116 | try { |
| 7117 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7118 | } catch (NoSuchElementException ex) { |
| 7119 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7120 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7121 | } finally { |
| 7122 | Binder.restoreCallingIdentity(identity); |
| 7123 | } |
| 7124 | } |
| 7125 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7126 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7127 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7128 | enforceModifyPermission(); |
| 7129 | |
| 7130 | final long identity = Binder.clearCallingIdentity(); |
| 7131 | try { |
| 7132 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7133 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7134 | .commit(); |
| 7135 | } finally { |
| 7136 | Binder.restoreCallingIdentity(identity); |
| 7137 | } |
| 7138 | } |
| 7139 | |
| 7140 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7141 | @TelephonyManager.IsMultiSimSupportedResult |
| 7142 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7144 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 7145 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7146 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7147 | |
| 7148 | final long identity = Binder.clearCallingIdentity(); |
| 7149 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7150 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7151 | } finally { |
| 7152 | Binder.restoreCallingIdentity(identity); |
| 7153 | } |
| 7154 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7155 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7156 | @TelephonyManager.IsMultiSimSupportedResult |
| 7157 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7158 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7159 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7160 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7161 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7162 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7163 | } |
| 7164 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7165 | // supported by the modem, indicate that it is restricted. |
| 7166 | PhoneCapability staticCapability = |
| 7167 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7168 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7169 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7170 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7171 | } |
| 7172 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7173 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7174 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7175 | } |
| 7176 | // Check if support of multiple SIMs is restricted by carrier |
| 7177 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7178 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7179 | } |
| 7180 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7181 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7182 | } |
| 7183 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7184 | /** |
| 7185 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7186 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7187 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7188 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7189 | * @param numOfSims number of active sims we want to switch to |
| 7190 | */ |
| 7191 | @Override |
| 7192 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7193 | if (numOfSims == 1) { |
| 7194 | enforceModifyPermission(); |
| 7195 | } else { |
| 7196 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7197 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7198 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7199 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7200 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7201 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7202 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7203 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7204 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7205 | return; |
| 7206 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7207 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7208 | } finally { |
| 7209 | Binder.restoreCallingIdentity(identity); |
| 7210 | } |
| 7211 | } |
| 7212 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7213 | @Override |
| 7214 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7215 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7216 | Phone phone = getPhone(subId); |
| 7217 | if (phone == null) { |
| 7218 | return false; |
| 7219 | } |
| 7220 | final long identity = Binder.clearCallingIdentity(); |
| 7221 | try { |
| 7222 | UiccCard uiccCard = phone.getUiccCard(); |
| 7223 | if (uiccCard == null) { |
| 7224 | return false; |
| 7225 | } |
| 7226 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7227 | if (uiccProfile == null) { |
| 7228 | return false; |
| 7229 | } |
| 7230 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7231 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7232 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7233 | } |
| 7234 | return false; |
| 7235 | } finally { |
| 7236 | Binder.restoreCallingIdentity(identity); |
| 7237 | } |
| 7238 | } |
| 7239 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7240 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7241 | * Get whether making changes to modem configurations will trigger reboot. |
| 7242 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7243 | */ |
| 7244 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7245 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 7246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 7247 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 7248 | return false; |
| 7249 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7250 | final long identity = Binder.clearCallingIdentity(); |
| 7251 | try { |
| 7252 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7253 | } finally { |
| 7254 | Binder.restoreCallingIdentity(identity); |
| 7255 | } |
| 7256 | } |
| 7257 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7258 | private void updateModemStateMetrics() { |
| 7259 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7260 | // TODO: check the state for each modem if the api is ready. |
| 7261 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7262 | } |
| 7263 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7264 | @Override |
| 7265 | public int[] getSlotsMapping() { |
| 7266 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7267 | |
| 7268 | final long identity = Binder.clearCallingIdentity(); |
| 7269 | try { |
| 7270 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7271 | // All logical slots should have a mapping to a physical slot. |
| 7272 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7273 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7274 | for (int i = 0; i < slotInfos.length; i++) { |
| 7275 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7276 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7277 | } |
| 7278 | } |
| 7279 | return logicalSlotsMapping; |
| 7280 | } finally { |
| 7281 | Binder.restoreCallingIdentity(identity); |
| 7282 | } |
| 7283 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7284 | |
| 7285 | /** |
| 7286 | * Get the IRadio HAL Version |
| 7287 | */ |
| 7288 | @Override |
| 7289 | public int getRadioHalVersion() { |
| 7290 | Phone phone = getDefaultPhone(); |
| 7291 | if (phone == null) return -1; |
| 7292 | HalVersion hv = phone.getHalVersion(); |
| 7293 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7294 | return hv.major * 100 + hv.minor; |
| 7295 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7296 | |
| 7297 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7298 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7299 | * corresponding network requests on a subId. |
| 7300 | * |
| 7301 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7302 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7303 | * 2) APN is un-metered for this subscription, or |
| 7304 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7305 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7306 | * |
| 7307 | * @return whether data is allowed for a apn type. |
| 7308 | * |
| 7309 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7310 | */ |
| 7311 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7312 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7313 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7314 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7315 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7316 | } |
| 7317 | |
| 7318 | // Now that all security checks passes, perform the operation as ourselves. |
| 7319 | final long identity = Binder.clearCallingIdentity(); |
| 7320 | try { |
| 7321 | Phone phone = getPhone(subId); |
| 7322 | if (phone == null) return false; |
| 7323 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7324 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7325 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7326 | } finally { |
| 7327 | Binder.restoreCallingIdentity(identity); |
| 7328 | } |
| 7329 | } |
| 7330 | |
| 7331 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7332 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7333 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7334 | |
| 7335 | // Now that all security checks passes, perform the operation as ourselves. |
| 7336 | final long identity = Binder.clearCallingIdentity(); |
| 7337 | try { |
| 7338 | Phone phone = getPhone(subId); |
| 7339 | if (phone == null) return true; // By default return true. |
| 7340 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7341 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7342 | } finally { |
| 7343 | Binder.restoreCallingIdentity(identity); |
| 7344 | } |
| 7345 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7346 | |
| 7347 | @Override |
| 7348 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7349 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7350 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7351 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7352 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7353 | } |
| 7354 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7355 | Intent intent = new Intent(); |
| 7356 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7357 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7358 | // Bring up choose default SMS subscription dialog right now |
| 7359 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7360 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7361 | mApp.startActivity(intent); |
| 7362 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7363 | |
| 7364 | @Override |
| 7365 | public String getMmsUAProfUrl(int subId) { |
| 7366 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7367 | final long identity = Binder.clearCallingIdentity(); |
| 7368 | try { |
| 7369 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7370 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7371 | } finally { |
| 7372 | Binder.restoreCallingIdentity(identity); |
| 7373 | } |
| 7374 | } |
| 7375 | |
| 7376 | @Override |
| 7377 | public String getMmsUserAgent(int subId) { |
| 7378 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7379 | final long identity = Binder.clearCallingIdentity(); |
| 7380 | try { |
| 7381 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7382 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7383 | } finally { |
| 7384 | Binder.restoreCallingIdentity(identity); |
| 7385 | } |
| 7386 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7387 | |
| 7388 | @Override |
| 7389 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7390 | enforceModifyPermission(); |
| 7391 | |
| 7392 | // Now that all security checks passes, perform the operation as ourselves. |
| 7393 | final long identity = Binder.clearCallingIdentity(); |
| 7394 | try { |
| 7395 | Phone phone = getPhone(subId); |
| 7396 | if (phone == null) return false; |
| 7397 | |
| 7398 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7399 | } finally { |
| 7400 | Binder.restoreCallingIdentity(identity); |
| 7401 | } |
| 7402 | } |
| 7403 | |
| 7404 | @Override |
| 7405 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7406 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7407 | |
| 7408 | // Now that all security checks passes, perform the operation as ourselves. |
| 7409 | final long identity = Binder.clearCallingIdentity(); |
| 7410 | try { |
| 7411 | Phone phone = getPhone(subId); |
| 7412 | if (phone == null) return false; |
| 7413 | |
| 7414 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7415 | } finally { |
| 7416 | Binder.restoreCallingIdentity(identity); |
| 7417 | } |
| 7418 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7419 | } |