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; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 47 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 48 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 49 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 51 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 52 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 54 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 55 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 56 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 57 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 58 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 59 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 60 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 61 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 62 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 63 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 65 | import android.telephony.CellInfoGsm; |
| 66 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 67 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 68 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 69 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 70 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 71 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 72 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 73 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 74 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 75 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 76 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 77 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 78 | import android.telephony.RadioAccessSpecifier; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 79 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 80 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 81 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 82 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 83 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 84 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 85 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 87 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 88 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 89 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 90 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 91 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 92 | import android.telephony.data.ApnSetting; |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 93 | import android.telephony.data.ApnSetting.ApnType; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 94 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 95 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 96 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 97 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 98 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 99 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 101 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 102 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 104 | import android.telephony.ims.feature.MmTelFeature; |
| 105 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 106 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 107 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 108 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 110 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 111 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 112 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 113 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 114 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 115 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 116 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 119 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 120 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 129 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.SmsApplication; |
| 142 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.uicc.IccIoResult; |
| 153 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 161 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 162 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 163 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 164 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 165 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 166 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 167 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 168 | import java.io.FileDescriptor; |
| 169 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 170 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 171 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 172 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 173 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 174 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 175 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 176 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 177 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 178 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 179 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 | |
| 181 | /** |
| 182 | * Implementation of the ITelephony interface. |
| 183 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 184 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 186 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 187 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 188 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | |
| 190 | // Message codes used with mMainThreadHandler |
| 191 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 192 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 193 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 194 | private static final int CMD_OPEN_CHANNEL = 9; |
| 195 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 196 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 197 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 198 | private static final int CMD_NV_READ_ITEM = 13; |
| 199 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 200 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 201 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 202 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 203 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 204 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 205 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 206 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 207 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 208 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 209 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 210 | private static final int CMD_SEND_ENVELOPE = 25; |
| 211 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 212 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 213 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 214 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 215 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 216 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 217 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 218 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 219 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 220 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 221 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 222 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 223 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 224 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 225 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 226 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 227 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 228 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 229 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 230 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 231 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 232 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 233 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 234 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 235 | private static final int CMD_SWITCH_SLOTS = 50; |
| 236 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 237 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 238 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 239 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 240 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 241 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 242 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 243 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 244 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 245 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 246 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 247 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 248 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 249 | private static final int CMD_MODEM_REBOOT = 64; |
| 250 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 251 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 252 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 253 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 254 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 255 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 256 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 257 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 258 | // Parameters of select command. |
| 259 | private static final int SELECT_COMMAND = 0xA4; |
| 260 | private static final int SELECT_P1 = 0x04; |
| 261 | private static final int SELECT_P2 = 0; |
| 262 | private static final int SELECT_P3 = 0x10; |
| 263 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 264 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 265 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 266 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 267 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 268 | /** The singleton instance. */ |
| 269 | private static PhoneInterfaceManager sInstance; |
| 270 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 271 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 272 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 273 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 274 | private AppOpsManager mAppOps; |
| 275 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 276 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 277 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 278 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 279 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 280 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 281 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 282 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 283 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 284 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 285 | // String to store multi SIM allowed |
| 286 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 287 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 288 | // The AID of ISD-R. |
| 289 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 290 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 291 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 292 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 293 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 294 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 295 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 296 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 297 | * A request object to use for transmitting data to an ICC. |
| 298 | */ |
| 299 | private static final class IccAPDUArgument { |
| 300 | public int channel, cla, command, p1, p2, p3; |
| 301 | public String data; |
| 302 | |
| 303 | public IccAPDUArgument(int channel, int cla, int command, |
| 304 | int p1, int p2, int p3, String data) { |
| 305 | this.channel = channel; |
| 306 | this.cla = cla; |
| 307 | this.command = command; |
| 308 | this.p1 = p1; |
| 309 | this.p2 = p2; |
| 310 | this.p3 = p3; |
| 311 | this.data = data; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 316 | * A request object to use for transmitting data to an ICC. |
| 317 | */ |
| 318 | private static final class ManualNetworkSelectionArgument { |
| 319 | public OperatorInfo operatorInfo; |
| 320 | public boolean persistSelection; |
| 321 | |
| 322 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 323 | this.operatorInfo = operatorInfo; |
| 324 | this.persistSelection = persistSelection; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 329 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 330 | * request after sending. The main thread will notify the request when it is complete. |
| 331 | */ |
| 332 | private static final class MainThreadRequest { |
| 333 | /** The argument to use for the request */ |
| 334 | public Object argument; |
| 335 | /** The result of the request that is run on the main thread */ |
| 336 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 337 | // The subscriber id that this request applies to. Defaults to |
| 338 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 339 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 340 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 341 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 342 | public Phone phone; |
| 343 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 344 | public WorkSource workSource; |
| 345 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 346 | public MainThreadRequest(Object argument) { |
| 347 | this.argument = argument; |
| 348 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 349 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 350 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 351 | this.argument = argument; |
| 352 | if (phone != null) { |
| 353 | this.phone = phone; |
| 354 | } |
| 355 | this.workSource = workSource; |
| 356 | } |
| 357 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 358 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 359 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 360 | if (subId != null) { |
| 361 | this.subId = subId; |
| 362 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 363 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 364 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 367 | private static final class IncomingThirdPartyCallArgs { |
| 368 | public final ComponentName component; |
| 369 | public final String callId; |
| 370 | public final String callerDisplayName; |
| 371 | |
| 372 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 373 | String callerDisplayName) { |
| 374 | this.component = component; |
| 375 | this.callId = callId; |
| 376 | this.callerDisplayName = callerDisplayName; |
| 377 | } |
| 378 | } |
| 379 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 380 | /** |
| 381 | * A handler that processes messages on the main thread in the phone process. Since many |
| 382 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 383 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 384 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 385 | * on, which will be notified when the operation completes and will contain the result of the |
| 386 | * request. |
| 387 | * |
| 388 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 389 | * note that request.result must be set to something non-null for the calling thread to |
| 390 | * unblock. |
| 391 | */ |
| 392 | private final class MainThreadHandler extends Handler { |
| 393 | @Override |
| 394 | public void handleMessage(Message msg) { |
| 395 | MainThreadRequest request; |
| 396 | Message onCompleted; |
| 397 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 398 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 399 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 400 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 401 | |
| 402 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 403 | case CMD_HANDLE_USSD_REQUEST: { |
| 404 | request = (MainThreadRequest) msg.obj; |
| 405 | final Phone phone = getPhoneFromRequest(request); |
| 406 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 407 | String ussdRequest = ussdObject.first; |
| 408 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 409 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 410 | if (!isUssdApiAllowed(request.subId)) { |
| 411 | // Carrier does not support use of this API, return failure. |
| 412 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 413 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 414 | Bundle returnData = new Bundle(); |
| 415 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 416 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 417 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 418 | request.result = true; |
| 419 | notifyRequester(request); |
| 420 | return; |
| 421 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 422 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 423 | try { |
| 424 | request.result = phone != null |
| 425 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 426 | } catch (CallStateException cse) { |
| 427 | request.result = false; |
| 428 | } |
| 429 | // Wake up the requesting thread |
| 430 | notifyRequester(request); |
| 431 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 434 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 435 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 436 | final Phone phone = getPhoneFromRequest(request); |
| 437 | request.result = phone != null ? |
| 438 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 439 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 440 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 441 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 443 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 445 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 446 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 447 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 448 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 449 | if (uiccCard == null) { |
| 450 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 451 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 452 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 453 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 454 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 455 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 456 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 457 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 458 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 459 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 460 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 461 | break; |
| 462 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 464 | ar = (AsyncResult) msg.obj; |
| 465 | request = (MainThreadRequest) ar.userObj; |
| 466 | if (ar.exception == null && ar.result != null) { |
| 467 | request.result = ar.result; |
| 468 | } else { |
| 469 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 470 | if (ar.result == null) { |
| 471 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 472 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 473 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 474 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 475 | } else { |
| 476 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 477 | } |
| 478 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 479 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 480 | break; |
| 481 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 482 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 483 | request = (MainThreadRequest) msg.obj; |
| 484 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 485 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 486 | if (uiccCard == null) { |
| 487 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 488 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 489 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 490 | } else { |
| 491 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 492 | request); |
| 493 | uiccCard.iccTransmitApduBasicChannel( |
| 494 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 495 | iccArgument.p3, iccArgument.data, onCompleted); |
| 496 | } |
| 497 | break; |
| 498 | |
| 499 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 500 | ar = (AsyncResult) msg.obj; |
| 501 | request = (MainThreadRequest) ar.userObj; |
| 502 | if (ar.exception == null && ar.result != null) { |
| 503 | request.result = ar.result; |
| 504 | } else { |
| 505 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 506 | if (ar.result == null) { |
| 507 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 508 | } else if (ar.exception instanceof CommandException) { |
| 509 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 510 | ar.exception); |
| 511 | } else { |
| 512 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 513 | } |
| 514 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 515 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | break; |
| 517 | |
| 518 | case CMD_EXCHANGE_SIM_IO: |
| 519 | request = (MainThreadRequest) msg.obj; |
| 520 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 521 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | if (uiccCard == null) { |
| 523 | loge("iccExchangeSimIO: No UICC"); |
| 524 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | } else { |
| 527 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 528 | request); |
| 529 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 530 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 531 | iccArgument.data, onCompleted); |
| 532 | } |
| 533 | break; |
| 534 | |
| 535 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 536 | ar = (AsyncResult) msg.obj; |
| 537 | request = (MainThreadRequest) ar.userObj; |
| 538 | if (ar.exception == null && ar.result != null) { |
| 539 | request.result = ar.result; |
| 540 | } else { |
| 541 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 542 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 543 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 544 | break; |
| 545 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 546 | case CMD_SEND_ENVELOPE: |
| 547 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 548 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 549 | if (uiccCard == null) { |
| 550 | loge("sendEnvelopeWithStatus: No UICC"); |
| 551 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 552 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 553 | } else { |
| 554 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 555 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 556 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 557 | break; |
| 558 | |
| 559 | case EVENT_SEND_ENVELOPE_DONE: |
| 560 | ar = (AsyncResult) msg.obj; |
| 561 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 562 | if (ar.exception == null && ar.result != null) { |
| 563 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 564 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 565 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 566 | if (ar.result == null) { |
| 567 | loge("sendEnvelopeWithStatus: Empty response"); |
| 568 | } else if (ar.exception instanceof CommandException) { |
| 569 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 570 | ar.exception); |
| 571 | } else { |
| 572 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 573 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 574 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 575 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 576 | break; |
| 577 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 578 | case CMD_OPEN_CHANNEL: |
| 579 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 580 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 581 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 582 | if (uiccCard == null) { |
| 583 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 584 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 585 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 586 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 587 | } else { |
| 588 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 589 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 590 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 591 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 592 | break; |
| 593 | |
| 594 | case EVENT_OPEN_CHANNEL_DONE: |
| 595 | ar = (AsyncResult) msg.obj; |
| 596 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 598 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 599 | int[] result = (int[]) ar.result; |
| 600 | int channelId = result[0]; |
| 601 | byte[] selectResponse = null; |
| 602 | if (result.length > 1) { |
| 603 | selectResponse = new byte[result.length - 1]; |
| 604 | for (int i = 1; i < result.length; ++i) { |
| 605 | selectResponse[i - 1] = (byte) result[i]; |
| 606 | } |
| 607 | } |
| 608 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 609 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 611 | if (ar.result == null) { |
| 612 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 613 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 614 | if (ar.exception != null) { |
| 615 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 616 | } |
| 617 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 618 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 619 | if (ar.exception instanceof CommandException) { |
| 620 | CommandException.Error error = |
| 621 | ((CommandException) (ar.exception)).getCommandError(); |
| 622 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 623 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 624 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 625 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 629 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 631 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | break; |
| 634 | |
| 635 | case CMD_CLOSE_CHANNEL: |
| 636 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 637 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 638 | if (uiccCard == null) { |
| 639 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 640 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 641 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 642 | } else { |
| 643 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 644 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 645 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | break; |
| 647 | |
| 648 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 649 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 650 | break; |
| 651 | |
| 652 | case CMD_NV_READ_ITEM: |
| 653 | request = (MainThreadRequest) msg.obj; |
| 654 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 655 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 656 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 657 | break; |
| 658 | |
| 659 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | ar = (AsyncResult) msg.obj; |
| 661 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | if (ar.exception == null && ar.result != null) { |
| 663 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 665 | request.result = ""; |
| 666 | if (ar.result == null) { |
| 667 | loge("nvReadItem: Empty response"); |
| 668 | } else if (ar.exception instanceof CommandException) { |
| 669 | loge("nvReadItem: CommandException: " + |
| 670 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 672 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | } |
| 674 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 675 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | break; |
| 677 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | case CMD_NV_WRITE_ITEM: |
| 679 | request = (MainThreadRequest) msg.obj; |
| 680 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 681 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 682 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 683 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | break; |
| 685 | |
| 686 | case EVENT_NV_WRITE_ITEM_DONE: |
| 687 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 688 | break; |
| 689 | |
| 690 | case CMD_NV_WRITE_CDMA_PRL: |
| 691 | request = (MainThreadRequest) msg.obj; |
| 692 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 693 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | break; |
| 695 | |
| 696 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 697 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 698 | break; |
| 699 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 700 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 702 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 703 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 704 | break; |
| 705 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 706 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 707 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | break; |
| 709 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 710 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 711 | request = (MainThreadRequest) msg.obj; |
| 712 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 713 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 717 | ar = (AsyncResult) msg.obj; |
| 718 | request = (MainThreadRequest) ar.userObj; |
| 719 | if (ar.exception == null && ar.result != null) { |
| 720 | request.result = ar.result; // Integer |
| 721 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 722 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 723 | if (ar.result == null) { |
| 724 | loge("getPreferredNetworkType: Empty response"); |
| 725 | } else if (ar.exception instanceof CommandException) { |
| 726 | loge("getPreferredNetworkType: CommandException: " + |
| 727 | ar.exception); |
| 728 | } else { |
| 729 | loge("getPreferredNetworkType: Unknown exception"); |
| 730 | } |
| 731 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 732 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 736 | request = (MainThreadRequest) msg.obj; |
| 737 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 738 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 739 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 740 | break; |
| 741 | |
| 742 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 743 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 744 | break; |
| 745 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 746 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 747 | request = (MainThreadRequest)msg.obj; |
| 748 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 749 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 753 | ar = (AsyncResult)msg.obj; |
| 754 | request = (MainThreadRequest)ar.userObj; |
| 755 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 756 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 757 | break; |
| 758 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 759 | case CMD_SET_VOICEMAIL_NUMBER: |
| 760 | request = (MainThreadRequest) msg.obj; |
| 761 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 762 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 763 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 764 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 768 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 769 | break; |
| 770 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 771 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 772 | request = (MainThreadRequest) msg.obj; |
| 773 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 774 | request); |
| 775 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 776 | break; |
| 777 | |
| 778 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 779 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 780 | break; |
| 781 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 782 | case CMD_PERFORM_NETWORK_SCAN: |
| 783 | request = (MainThreadRequest) msg.obj; |
| 784 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 785 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 786 | break; |
| 787 | |
| 788 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 789 | ar = (AsyncResult) msg.obj; |
| 790 | request = (MainThreadRequest) ar.userObj; |
| 791 | CellNetworkScanResult cellScanResult; |
| 792 | if (ar.exception == null && ar.result != null) { |
| 793 | cellScanResult = new CellNetworkScanResult( |
| 794 | CellNetworkScanResult.STATUS_SUCCESS, |
| 795 | (List<OperatorInfo>) ar.result); |
| 796 | } else { |
| 797 | if (ar.result == null) { |
| 798 | loge("getCellNetworkScanResults: Empty response"); |
| 799 | } |
| 800 | if (ar.exception != null) { |
| 801 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 802 | } |
| 803 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 804 | if (ar.exception instanceof CommandException) { |
| 805 | CommandException.Error error = |
| 806 | ((CommandException) (ar.exception)).getCommandError(); |
| 807 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 808 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 809 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 810 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 811 | } |
| 812 | } |
| 813 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 814 | } |
| 815 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 816 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 817 | break; |
| 818 | |
| 819 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 820 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 821 | ManualNetworkSelectionArgument selArg = |
| 822 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 823 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 824 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 825 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 826 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 827 | break; |
| 828 | |
| 829 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 830 | ar = (AsyncResult) msg.obj; |
| 831 | request = (MainThreadRequest) ar.userObj; |
| 832 | if (ar.exception == null) { |
| 833 | request.result = true; |
| 834 | } else { |
| 835 | request.result = false; |
| 836 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 837 | } |
| 838 | notifyRequester(request); |
| 839 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 840 | break; |
| 841 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 842 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 843 | request = (MainThreadRequest) msg.obj; |
| 844 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 845 | if (defaultPhone != null) { |
| 846 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 847 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 848 | break; |
| 849 | |
| 850 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 851 | ar = (AsyncResult) msg.obj; |
| 852 | request = (MainThreadRequest) ar.userObj; |
| 853 | if (ar.exception == null && ar.result != null) { |
| 854 | request.result = ar.result; |
| 855 | } else { |
| 856 | if (ar.result == null) { |
| 857 | loge("queryModemActivityInfo: Empty response"); |
| 858 | } else if (ar.exception instanceof CommandException) { |
| 859 | loge("queryModemActivityInfo: CommandException: " + |
| 860 | ar.exception); |
| 861 | } else { |
| 862 | loge("queryModemActivityInfo: Unknown exception"); |
| 863 | } |
| 864 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 865 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 866 | if (request.result == null) { |
| 867 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 868 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 869 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 870 | break; |
| 871 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 872 | case CMD_SET_ALLOWED_CARRIERS: |
| 873 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 874 | CarrierRestrictionRules argument = |
| 875 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 876 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 877 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 878 | break; |
| 879 | |
| 880 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 881 | ar = (AsyncResult) msg.obj; |
| 882 | request = (MainThreadRequest) ar.userObj; |
| 883 | if (ar.exception == null && ar.result != null) { |
| 884 | request.result = ar.result; |
| 885 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 886 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 887 | if (ar.exception instanceof CommandException) { |
| 888 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 889 | CommandException.Error error = |
| 890 | ((CommandException) (ar.exception)).getCommandError(); |
| 891 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 892 | request.result = |
| 893 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 894 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 895 | } else { |
| 896 | loge("setAllowedCarriers: Unknown exception"); |
| 897 | } |
| 898 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 899 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 900 | break; |
| 901 | |
| 902 | case CMD_GET_ALLOWED_CARRIERS: |
| 903 | request = (MainThreadRequest) msg.obj; |
| 904 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 905 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 906 | break; |
| 907 | |
| 908 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 909 | ar = (AsyncResult) msg.obj; |
| 910 | request = (MainThreadRequest) ar.userObj; |
| 911 | if (ar.exception == null && ar.result != null) { |
| 912 | request.result = ar.result; |
| 913 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 914 | request.result = new IllegalStateException( |
| 915 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 916 | if (ar.result == null) { |
| 917 | loge("getAllowedCarriers: Empty response"); |
| 918 | } else if (ar.exception instanceof CommandException) { |
| 919 | loge("getAllowedCarriers: CommandException: " + |
| 920 | ar.exception); |
| 921 | } else { |
| 922 | loge("getAllowedCarriers: Unknown exception"); |
| 923 | } |
| 924 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 925 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 926 | break; |
| 927 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 928 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 929 | ar = (AsyncResult) msg.obj; |
| 930 | request = (MainThreadRequest) ar.userObj; |
| 931 | if (ar.exception == null && ar.result != null) { |
| 932 | request.result = ar.result; |
| 933 | } else { |
| 934 | request.result = new IllegalArgumentException( |
| 935 | "Failed to retrieve Forbidden Plmns"); |
| 936 | if (ar.result == null) { |
| 937 | loge("getForbiddenPlmns: Empty response"); |
| 938 | } else { |
| 939 | loge("getForbiddenPlmns: Unknown exception"); |
| 940 | } |
| 941 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 942 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 943 | break; |
| 944 | |
| 945 | case CMD_GET_FORBIDDEN_PLMNS: |
| 946 | request = (MainThreadRequest) msg.obj; |
| 947 | uiccCard = getUiccCardFromRequest(request); |
| 948 | if (uiccCard == null) { |
| 949 | loge("getForbiddenPlmns() UiccCard is null"); |
| 950 | request.result = new IllegalArgumentException( |
| 951 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 952 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 953 | break; |
| 954 | } |
| 955 | Integer appType = (Integer) request.argument; |
| 956 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 957 | if (uiccApp == null) { |
| 958 | loge("getForbiddenPlmns() no app with specified type -- " |
| 959 | + appType); |
| 960 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 961 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 962 | break; |
| 963 | } else { |
| 964 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 965 | + " specified type -- " + appType); |
| 966 | } |
| 967 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 968 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 969 | onCompleted); |
| 970 | break; |
| 971 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 972 | case CMD_SWITCH_SLOTS: |
| 973 | request = (MainThreadRequest) msg.obj; |
| 974 | int[] physicalSlots = (int[]) request.argument; |
| 975 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 976 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 977 | break; |
| 978 | |
| 979 | case EVENT_SWITCH_SLOTS_DONE: |
| 980 | ar = (AsyncResult) msg.obj; |
| 981 | request = (MainThreadRequest) ar.userObj; |
| 982 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 983 | notifyRequester(request); |
| 984 | break; |
| 985 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 986 | request = (MainThreadRequest) msg.obj; |
| 987 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 988 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 989 | break; |
| 990 | |
| 991 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 992 | ar = (AsyncResult) msg.obj; |
| 993 | request = (MainThreadRequest) ar.userObj; |
| 994 | if (ar.exception != null) { |
| 995 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 996 | } else { |
| 997 | int mode = ((int[]) ar.result)[0]; |
| 998 | if (mode == 0) { |
| 999 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1000 | } else { |
| 1001 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1002 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1003 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1004 | notifyRequester(request); |
| 1005 | break; |
| 1006 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1007 | request = (MainThreadRequest) msg.obj; |
| 1008 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1009 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1010 | break; |
| 1011 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1012 | ar = (AsyncResult) msg.obj; |
| 1013 | request = (MainThreadRequest) ar.userObj; |
| 1014 | if (ar.exception != null) { |
| 1015 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1016 | } else { |
| 1017 | request.result = ((int[]) ar.result)[0]; |
| 1018 | } |
| 1019 | notifyRequester(request); |
| 1020 | break; |
| 1021 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1022 | request = (MainThreadRequest) msg.obj; |
| 1023 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1024 | int mode = (int) request.argument; |
| 1025 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1026 | break; |
| 1027 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1028 | ar = (AsyncResult) msg.obj; |
| 1029 | request = (MainThreadRequest) ar.userObj; |
| 1030 | request.result = ar.exception == null; |
| 1031 | notifyRequester(request); |
| 1032 | break; |
| 1033 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1034 | request = (MainThreadRequest) msg.obj; |
| 1035 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1036 | int subscriptionMode = (int) request.argument; |
| 1037 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1038 | break; |
| 1039 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1040 | ar = (AsyncResult) msg.obj; |
| 1041 | request = (MainThreadRequest) ar.userObj; |
| 1042 | request.result = ar.exception == null; |
| 1043 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1044 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1045 | case CMD_GET_ALL_CELL_INFO: |
| 1046 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1047 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1048 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1049 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1050 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1051 | ar = (AsyncResult) msg.obj; |
| 1052 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1053 | // If a timeout occurs, the response will be null |
| 1054 | request.result = (ar.exception == null && ar.result != null) |
| 1055 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1056 | synchronized (request) { |
| 1057 | request.notifyAll(); |
| 1058 | } |
| 1059 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1060 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1061 | request = (MainThreadRequest) msg.obj; |
| 1062 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1063 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1064 | break; |
| 1065 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
| 1068 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1069 | try { |
| 1070 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1071 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1072 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1073 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1074 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1075 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1076 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1077 | } else { |
| 1078 | // use the result as returned |
| 1079 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1080 | } |
| 1081 | } catch (RemoteException re) { |
| 1082 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1083 | } |
| 1084 | break; |
| 1085 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1086 | request = (MainThreadRequest) msg.obj; |
| 1087 | WorkSource ws = (WorkSource) request.argument; |
| 1088 | Phone phone = getPhoneFromRequest(request); |
| 1089 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1090 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1091 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1092 | ar = (AsyncResult) msg.obj; |
| 1093 | request = (MainThreadRequest) ar.userObj; |
| 1094 | if (ar.exception == null) { |
| 1095 | request.result = ar.result; |
| 1096 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1097 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1098 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1099 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1100 | } |
| 1101 | |
| 1102 | synchronized (request) { |
| 1103 | request.notifyAll(); |
| 1104 | } |
| 1105 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1106 | case CMD_MODEM_REBOOT: |
| 1107 | request = (MainThreadRequest) msg.obj; |
| 1108 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1109 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1110 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1111 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1112 | handleNullReturnEvent(msg, "rebootModem"); |
| 1113 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1114 | case CMD_REQUEST_ENABLE_MODEM: |
| 1115 | request = (MainThreadRequest) msg.obj; |
| 1116 | boolean enable = (boolean) request.argument; |
| 1117 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1118 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1119 | PhoneConfigurationManager.getInstance() |
| 1120 | .enablePhone(request.phone, enable, onCompleted); |
| 1121 | break; |
| 1122 | case EVENT_ENABLE_MODEM_DONE: |
| 1123 | ar = (AsyncResult) msg.obj; |
| 1124 | request = (MainThreadRequest) ar.userObj; |
| 1125 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1126 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1127 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1128 | if ((boolean) request.result) { |
| 1129 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1130 | updateModemStateMetrics(); |
| 1131 | } else { |
| 1132 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1133 | + ar.exception); |
| 1134 | } |
| 1135 | notifyRequester(request); |
| 1136 | break; |
| 1137 | case CMD_GET_MODEM_STATUS: |
| 1138 | request = (MainThreadRequest) msg.obj; |
| 1139 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1140 | PhoneConfigurationManager.getInstance() |
| 1141 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1142 | break; |
| 1143 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1144 | ar = (AsyncResult) msg.obj; |
| 1145 | request = (MainThreadRequest) ar.userObj; |
| 1146 | int id = request.phone.getPhoneId(); |
| 1147 | if (ar.exception == null && ar.result != null) { |
| 1148 | request.result = ar.result; |
| 1149 | //update the cache as modem status has changed |
| 1150 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1151 | (boolean) request.result); |
| 1152 | } else { |
| 1153 | // Return true if modem status cannot be retrieved. For most cases, |
| 1154 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1155 | // and disable modem are not supported. Modem is always on. |
| 1156 | // TODO: this should be fixed in R to support a third |
| 1157 | // status UNKNOWN b/131631629 |
| 1158 | request.result = true; |
| 1159 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1160 | + ar.exception); |
| 1161 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1162 | notifyRequester(request); |
| 1163 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1164 | default: |
| 1165 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1166 | break; |
| 1167 | } |
| 1168 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1169 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1170 | private void notifyRequester(MainThreadRequest request) { |
| 1171 | synchronized (request) { |
| 1172 | request.notifyAll(); |
| 1173 | } |
| 1174 | } |
| 1175 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1176 | private void handleNullReturnEvent(Message msg, String command) { |
| 1177 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1178 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1179 | if (ar.exception == null) { |
| 1180 | request.result = true; |
| 1181 | } else { |
| 1182 | request.result = false; |
| 1183 | if (ar.exception instanceof CommandException) { |
| 1184 | loge(command + ": CommandException: " + ar.exception); |
| 1185 | } else { |
| 1186 | loge(command + ": Unknown exception"); |
| 1187 | } |
| 1188 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1189 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1190 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | /** |
| 1194 | * Posts the specified command to be executed on the main thread, |
| 1195 | * waits for the request to complete, and returns the result. |
| 1196 | * @see #sendRequestAsync |
| 1197 | */ |
| 1198 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1199 | return sendRequest( |
| 1200 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * Posts the specified command to be executed on the main thread, |
| 1205 | * waits for the request to complete, and returns the result. |
| 1206 | * @see #sendRequestAsync |
| 1207 | */ |
| 1208 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1209 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1210 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /** |
| 1214 | * Posts the specified command to be executed on the main thread, |
| 1215 | * waits for the request to complete, and returns the result. |
| 1216 | * @see #sendRequestAsync |
| 1217 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1218 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1219 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * Posts the specified command to be executed on the main thread, |
| 1224 | * waits for the request to complete, and returns the result. |
| 1225 | * @see #sendRequestAsync |
| 1226 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1227 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1228 | return sendRequest(command, argument, subId, null, workSource); |
| 1229 | } |
| 1230 | |
| 1231 | /** |
| 1232 | * Posts the specified command to be executed on the main thread, |
| 1233 | * waits for the request to complete, and returns the result. |
| 1234 | * @see #sendRequestAsync |
| 1235 | */ |
| 1236 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1237 | return sendRequest( |
| 1238 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * Posts the specified command to be executed on the main thread, |
| 1243 | * waits for the request to complete, and returns the result. |
| 1244 | * @see #sendRequestAsync |
| 1245 | */ |
| 1246 | private Object sendRequest( |
| 1247 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1248 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1249 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1250 | } |
| 1251 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1252 | MainThreadRequest request = null; |
| 1253 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1254 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1255 | } else if (phone != null) { |
| 1256 | request = new MainThreadRequest(argument, phone, workSource); |
| 1257 | } else { |
| 1258 | request = new MainThreadRequest(argument, subId, workSource); |
| 1259 | } |
| 1260 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1261 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1262 | msg.sendToTarget(); |
| 1263 | |
| 1264 | // Wait for the request to complete |
| 1265 | synchronized (request) { |
| 1266 | while (request.result == null) { |
| 1267 | try { |
| 1268 | request.wait(); |
| 1269 | } catch (InterruptedException e) { |
| 1270 | // Do nothing, go back and wait until the request is complete |
| 1271 | } |
| 1272 | } |
| 1273 | } |
| 1274 | return request.result; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1279 | * Posts the specified command to be executed on the main thread, and |
| 1280 | * returns immediately. |
| 1281 | * @see #sendRequest |
| 1282 | */ |
| 1283 | private void sendRequestAsync(int command) { |
| 1284 | mMainThreadHandler.sendEmptyMessage(command); |
| 1285 | } |
| 1286 | |
| 1287 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1288 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1289 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1290 | */ |
| 1291 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1292 | sendRequestAsync(command, argument, null, null); |
| 1293 | } |
| 1294 | |
| 1295 | /** |
| 1296 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1297 | * @see {@link #sendRequest(int,Object)} |
| 1298 | */ |
| 1299 | private void sendRequestAsync( |
| 1300 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1301 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1302 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1303 | msg.sendToTarget(); |
| 1304 | } |
| 1305 | |
| 1306 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1307 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1308 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1309 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1310 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1311 | synchronized (PhoneInterfaceManager.class) { |
| 1312 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1313 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1314 | } else { |
| 1315 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1316 | } |
| 1317 | return sInstance; |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1322 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1323 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1324 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1325 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1326 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1327 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1328 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1329 | mTelephonySharedPreferences = |
| 1330 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1331 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1332 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1333 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1334 | publish(); |
| 1335 | } |
| 1336 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1337 | private Phone getDefaultPhone() { |
| 1338 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1339 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1340 | } |
| 1341 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1342 | private void publish() { |
| 1343 | if (DBG) log("publish: " + this); |
| 1344 | |
| 1345 | ServiceManager.addService("phone", this); |
| 1346 | } |
| 1347 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1348 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1349 | if (request.phone != null) { |
| 1350 | return request.phone; |
| 1351 | } else { |
| 1352 | return getPhoneFromSubId(request.subId); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | private Phone getPhoneFromSubId(int subId) { |
| 1357 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1358 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1359 | } |
| 1360 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1361 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1362 | Phone phone = getPhoneFromRequest(request); |
| 1363 | return phone == null ? null : |
| 1364 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1365 | } |
| 1366 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1367 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1368 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1369 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1371 | |
| 1372 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1373 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1376 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1377 | if (DBG) log("dial: " + number); |
| 1378 | // No permission check needed here: This is just a wrapper around the |
| 1379 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1380 | // the UI before it does anything. |
| 1381 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1382 | final long identity = Binder.clearCallingIdentity(); |
| 1383 | try { |
| 1384 | String url = createTelUrl(number); |
| 1385 | if (url == null) { |
| 1386 | return; |
| 1387 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1388 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1389 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1390 | PhoneConstants.State state = mCM.getState(subId); |
| 1391 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1392 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1393 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1394 | mApp.startActivity(intent); |
| 1395 | } |
| 1396 | } finally { |
| 1397 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1402 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1405 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1406 | if (DBG) log("call: " + number); |
| 1407 | |
| 1408 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1409 | // need to do a permission check since we're calling startActivity() |
| 1410 | // from the context of the phone app. |
| 1411 | enforceCallPermission(); |
| 1412 | |
| 1413 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1414 | != AppOpsManager.MODE_ALLOWED) { |
| 1415 | return; |
| 1416 | } |
| 1417 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1418 | final long identity = Binder.clearCallingIdentity(); |
| 1419 | try { |
| 1420 | String url = createTelUrl(number); |
| 1421 | if (url == null) { |
| 1422 | return; |
| 1423 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1424 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1425 | boolean isValid = false; |
| 1426 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1427 | if (slist != null) { |
| 1428 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1429 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1430 | isValid = true; |
| 1431 | break; |
| 1432 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1433 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1434 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1435 | if (!isValid) { |
| 1436 | return; |
| 1437 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1439 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1440 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1441 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1442 | mApp.startActivity(intent); |
| 1443 | } finally { |
| 1444 | Binder.restoreCallingIdentity(identity); |
| 1445 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1448 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1449 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1450 | } |
| 1451 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1452 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1453 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1454 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1455 | } |
| 1456 | |
| 1457 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1458 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1461 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1462 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1463 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1464 | } |
| 1465 | |
| 1466 | /** {@hide} */ |
| 1467 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1468 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1471 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1472 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1473 | |
| 1474 | final long identity = Binder.clearCallingIdentity(); |
| 1475 | try { |
| 1476 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1477 | checkSimPin.start(); |
| 1478 | return checkSimPin.unlockSim(null, pin); |
| 1479 | } finally { |
| 1480 | Binder.restoreCallingIdentity(identity); |
| 1481 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1484 | /** {@hide} */ |
| 1485 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1486 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1489 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1490 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1491 | |
| 1492 | final long identity = Binder.clearCallingIdentity(); |
| 1493 | try { |
| 1494 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1495 | checkSimPuk.start(); |
| 1496 | return checkSimPuk.unlockSim(puk, pin); |
| 1497 | } finally { |
| 1498 | Binder.restoreCallingIdentity(identity); |
| 1499 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1503 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1504 | * a synchronous one. |
| 1505 | */ |
| 1506 | private static class UnlockSim extends Thread { |
| 1507 | |
| 1508 | private final IccCard mSimCard; |
| 1509 | |
| 1510 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1511 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1512 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1513 | |
| 1514 | // For replies from SimCard interface |
| 1515 | private Handler mHandler; |
| 1516 | |
| 1517 | // For async handler to identify request type |
| 1518 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1519 | |
| 1520 | public UnlockSim(IccCard simCard) { |
| 1521 | mSimCard = simCard; |
| 1522 | } |
| 1523 | |
| 1524 | @Override |
| 1525 | public void run() { |
| 1526 | Looper.prepare(); |
| 1527 | synchronized (UnlockSim.this) { |
| 1528 | mHandler = new Handler() { |
| 1529 | @Override |
| 1530 | public void handleMessage(Message msg) { |
| 1531 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1532 | switch (msg.what) { |
| 1533 | case SUPPLY_PIN_COMPLETE: |
| 1534 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1535 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1536 | mRetryCount = msg.arg1; |
| 1537 | if (ar.exception != null) { |
| 1538 | if (ar.exception instanceof CommandException && |
| 1539 | ((CommandException)(ar.exception)).getCommandError() |
| 1540 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1541 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1542 | } else { |
| 1543 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1544 | } |
| 1545 | } else { |
| 1546 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1547 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1548 | mDone = true; |
| 1549 | UnlockSim.this.notifyAll(); |
| 1550 | } |
| 1551 | break; |
| 1552 | } |
| 1553 | } |
| 1554 | }; |
| 1555 | UnlockSim.this.notifyAll(); |
| 1556 | } |
| 1557 | Looper.loop(); |
| 1558 | } |
| 1559 | |
| 1560 | /* |
| 1561 | * Use PIN or PUK to unlock SIM card |
| 1562 | * |
| 1563 | * If PUK is null, unlock SIM card with PIN |
| 1564 | * |
| 1565 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1566 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1567 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1568 | |
| 1569 | while (mHandler == null) { |
| 1570 | try { |
| 1571 | wait(); |
| 1572 | } catch (InterruptedException e) { |
| 1573 | Thread.currentThread().interrupt(); |
| 1574 | } |
| 1575 | } |
| 1576 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1577 | |
| 1578 | if (puk == null) { |
| 1579 | mSimCard.supplyPin(pin, callback); |
| 1580 | } else { |
| 1581 | mSimCard.supplyPuk(puk, pin, callback); |
| 1582 | } |
| 1583 | |
| 1584 | while (!mDone) { |
| 1585 | try { |
| 1586 | Log.d(LOG_TAG, "wait for done"); |
| 1587 | wait(); |
| 1588 | } catch (InterruptedException e) { |
| 1589 | // Restore the interrupted status |
| 1590 | Thread.currentThread().interrupt(); |
| 1591 | } |
| 1592 | } |
| 1593 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1594 | int[] resultArray = new int[2]; |
| 1595 | resultArray[0] = mResult; |
| 1596 | resultArray[1] = mRetryCount; |
| 1597 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1602 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1603 | |
| 1604 | } |
| 1605 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1606 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1607 | // No permission check needed here: this call is harmless, and it's |
| 1608 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1609 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1610 | final long identity = Binder.clearCallingIdentity(); |
| 1611 | try { |
| 1612 | final Phone phone = getPhone(subId); |
| 1613 | if (phone != null) { |
| 1614 | phone.updateServiceLocation(); |
| 1615 | } |
| 1616 | } finally { |
| 1617 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1618 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1621 | @Override |
| 1622 | public boolean isRadioOn(String callingPackage) { |
| 1623 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1626 | @Override |
| 1627 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1628 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1629 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1630 | return false; |
| 1631 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1632 | |
| 1633 | final long identity = Binder.clearCallingIdentity(); |
| 1634 | try { |
| 1635 | return isRadioOnForSubscriber(subId); |
| 1636 | } finally { |
| 1637 | Binder.restoreCallingIdentity(identity); |
| 1638 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1642 | final long identity = Binder.clearCallingIdentity(); |
| 1643 | try { |
| 1644 | final Phone phone = getPhone(subId); |
| 1645 | if (phone != null) { |
| 1646 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1647 | } else { |
| 1648 | return false; |
| 1649 | } |
| 1650 | } finally { |
| 1651 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1652 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1656 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1658 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1659 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1660 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1661 | |
| 1662 | final long identity = Binder.clearCallingIdentity(); |
| 1663 | try { |
| 1664 | final Phone phone = getPhone(subId); |
| 1665 | if (phone != null) { |
| 1666 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1667 | } |
| 1668 | } finally { |
| 1669 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1670 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1674 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1677 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1678 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1679 | |
| 1680 | final long identity = Binder.clearCallingIdentity(); |
| 1681 | try { |
| 1682 | final Phone phone = getPhone(subId); |
| 1683 | if (phone == null) { |
| 1684 | return false; |
| 1685 | } |
| 1686 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1687 | toggleRadioOnOffForSubscriber(subId); |
| 1688 | } |
| 1689 | return true; |
| 1690 | } finally { |
| 1691 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1692 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1693 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1694 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1695 | public boolean needMobileRadioShutdown() { |
| 1696 | /* |
| 1697 | * If any of the Radios are available, it will need to be |
| 1698 | * shutdown. So return true if any Radio is available. |
| 1699 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1700 | final long identity = Binder.clearCallingIdentity(); |
| 1701 | try { |
| 1702 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1703 | Phone phone = PhoneFactory.getPhone(i); |
| 1704 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1705 | } |
| 1706 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1707 | return false; |
| 1708 | } finally { |
| 1709 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1710 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1713 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1714 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1715 | enforceModifyPermission(); |
| 1716 | |
| 1717 | final long identity = Binder.clearCallingIdentity(); |
| 1718 | try { |
| 1719 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1720 | logv("Shutting down Phone " + i); |
| 1721 | shutdownRadioUsingPhoneId(i); |
| 1722 | } |
| 1723 | } finally { |
| 1724 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1729 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1730 | if (phone != null && phone.isRadioAvailable()) { |
| 1731 | phone.shutdownRadio(); |
| 1732 | } |
| 1733 | } |
| 1734 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1735 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1736 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1737 | |
| 1738 | final long identity = Binder.clearCallingIdentity(); |
| 1739 | try { |
| 1740 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1741 | if (defaultPhone != null) { |
| 1742 | defaultPhone.setRadioPower(turnOn); |
| 1743 | return true; |
| 1744 | } else { |
| 1745 | loge("There's no default phone."); |
| 1746 | return false; |
| 1747 | } |
| 1748 | } finally { |
| 1749 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1750 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1753 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1754 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1755 | |
| 1756 | final long identity = Binder.clearCallingIdentity(); |
| 1757 | try { |
| 1758 | final Phone phone = getPhone(subId); |
| 1759 | if (phone != null) { |
| 1760 | phone.setRadioPower(turnOn); |
| 1761 | return true; |
| 1762 | } else { |
| 1763 | return false; |
| 1764 | } |
| 1765 | } finally { |
| 1766 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1767 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1770 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1771 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1772 | public boolean enableDataConnectivity() { |
| 1773 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1774 | |
| 1775 | final long identity = Binder.clearCallingIdentity(); |
| 1776 | try { |
| 1777 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1778 | final Phone phone = getPhone(subId); |
| 1779 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1780 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1781 | return true; |
| 1782 | } else { |
| 1783 | return false; |
| 1784 | } |
| 1785 | } finally { |
| 1786 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1787 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1790 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1791 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1792 | public boolean disableDataConnectivity() { |
| 1793 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1794 | |
| 1795 | final long identity = Binder.clearCallingIdentity(); |
| 1796 | try { |
| 1797 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1798 | final Phone phone = getPhone(subId); |
| 1799 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1800 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1801 | return true; |
| 1802 | } else { |
| 1803 | return false; |
| 1804 | } |
| 1805 | } finally { |
| 1806 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1807 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1810 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1811 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1812 | final long identity = Binder.clearCallingIdentity(); |
| 1813 | try { |
| 1814 | final Phone phone = getPhone(subId); |
| 1815 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1816 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1817 | } else { |
| 1818 | return false; |
| 1819 | } |
| 1820 | } finally { |
| 1821 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1822 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1826 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1829 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1830 | enforceCallPermission(); |
| 1831 | |
| 1832 | final long identity = Binder.clearCallingIdentity(); |
| 1833 | try { |
| 1834 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1835 | return; |
| 1836 | } |
| 1837 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1838 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1839 | } finally { |
| 1840 | Binder.restoreCallingIdentity(identity); |
| 1841 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1842 | }; |
| 1843 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1844 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1845 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1846 | |
| 1847 | final long identity = Binder.clearCallingIdentity(); |
| 1848 | try { |
| 1849 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1850 | return false; |
| 1851 | } |
| 1852 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1853 | } finally { |
| 1854 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1855 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1858 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1859 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1862 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1863 | final long identity = Binder.clearCallingIdentity(); |
| 1864 | try { |
| 1865 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1866 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1867 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1868 | } finally { |
| 1869 | Binder.restoreCallingIdentity(identity); |
| 1870 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1873 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1874 | public int getDataState() { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame^] | 1875 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1876 | } |
| 1877 | |
| 1878 | @Override |
| 1879 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1880 | final long identity = Binder.clearCallingIdentity(); |
| 1881 | try { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame^] | 1882 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1883 | if (phone != null) { |
| 1884 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1885 | } else { |
| 1886 | return PhoneConstantConversions.convertDataState( |
| 1887 | PhoneConstants.DataState.DISCONNECTED); |
| 1888 | } |
| 1889 | } finally { |
| 1890 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1891 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1894 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1895 | public int getDataActivity() { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame^] | 1896 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1897 | } |
| 1898 | |
| 1899 | @Override |
| 1900 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1901 | final long identity = Binder.clearCallingIdentity(); |
| 1902 | try { |
Nathan Harold | cbce726 | 2019-06-14 16:58:30 -0700 | [diff] [blame^] | 1903 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1904 | if (phone != null) { |
| 1905 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1906 | } else { |
| 1907 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1908 | } |
| 1909 | } finally { |
| 1910 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1911 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1915 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1916 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1917 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1918 | |
| 1919 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1920 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1921 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1922 | .setCallingPackage(callingPackage) |
| 1923 | .setCallingPid(Binder.getCallingPid()) |
| 1924 | .setCallingUid(Binder.getCallingUid()) |
| 1925 | .setMethod("getCellLocation") |
| 1926 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1927 | .build()); |
| 1928 | switch (locationResult) { |
| 1929 | case DENIED_HARD: |
| 1930 | throw new SecurityException("Not allowed to access cell location"); |
| 1931 | case DENIED_SOFT: |
| 1932 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1935 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1936 | final long identity = Binder.clearCallingIdentity(); |
| 1937 | try { |
| 1938 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1939 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1940 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1941 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1942 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1943 | return data; |
| 1944 | } finally { |
| 1945 | Binder.restoreCallingIdentity(identity); |
| 1946 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1949 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1950 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1951 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1952 | // registered cell info, so return a NULL country instead. |
| 1953 | final long identity = Binder.clearCallingIdentity(); |
| 1954 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1955 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1956 | // Get default phone in this case. |
| 1957 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1958 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1959 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1960 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1961 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1962 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1963 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1964 | return ""; |
| 1965 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1966 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1967 | if (phone != null) { |
| 1968 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1969 | if (sst != null) { |
| 1970 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1971 | if (lt != null) { |
| 1972 | return lt.getCurrentCountry(); |
| 1973 | } |
| 1974 | } |
| 1975 | } |
| 1976 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1977 | } finally { |
| 1978 | Binder.restoreCallingIdentity(identity); |
| 1979 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1983 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1984 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1987 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1988 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1989 | mApp.enforceCallingOrSelfPermission( |
| 1990 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1991 | |
| 1992 | final long identity = Binder.clearCallingIdentity(); |
| 1993 | try { |
| 1994 | final Phone phone = getPhone(subId); |
| 1995 | if (phone != null) { |
| 1996 | phone.enableLocationUpdates(); |
| 1997 | } |
| 1998 | } finally { |
| 1999 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2000 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | @Override |
| 2004 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2005 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2008 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2009 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2010 | mApp.enforceCallingOrSelfPermission( |
| 2011 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2012 | |
| 2013 | final long identity = Binder.clearCallingIdentity(); |
| 2014 | try { |
| 2015 | final Phone phone = getPhone(subId); |
| 2016 | if (phone != null) { |
| 2017 | phone.disableLocationUpdates(); |
| 2018 | } |
| 2019 | } finally { |
| 2020 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2021 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2024 | /** |
| 2025 | * Returns the target SDK version number for a given package name. |
| 2026 | * |
| 2027 | * @return target SDK if the package is found or INT_MAX. |
| 2028 | */ |
| 2029 | private int getTargetSdk(String packageName) { |
| 2030 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2031 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 2032 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2033 | if (ai != null) return ai.targetSdkVersion; |
| 2034 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 2035 | } |
| 2036 | return Integer.MAX_VALUE; |
| 2037 | } |
| 2038 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2039 | @Override |
| 2040 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2041 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 2042 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2043 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2044 | throw new SecurityException( |
| 2045 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2046 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2047 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2048 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 2049 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2050 | return null; |
| 2051 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2052 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2053 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2054 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2055 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2056 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2057 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2058 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2059 | for (CellInfo ci : info) { |
| 2060 | if (ci instanceof CellInfoGsm) { |
| 2061 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2062 | } else if (ci instanceof CellInfoWcdma) { |
| 2063 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2064 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2065 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2066 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2069 | private List<CellInfo> getCachedCellInfo() { |
| 2070 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2071 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2072 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2073 | if (info != null) cellInfos.addAll(info); |
| 2074 | } |
| 2075 | return cellInfos; |
| 2076 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2077 | |
| 2078 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2079 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2080 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2081 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2082 | |
| 2083 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2084 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2085 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2086 | .setCallingPackage(callingPackage) |
| 2087 | .setCallingPid(Binder.getCallingPid()) |
| 2088 | .setCallingUid(Binder.getCallingUid()) |
| 2089 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2090 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2091 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2092 | .build()); |
| 2093 | switch (locationResult) { |
| 2094 | case DENIED_HARD: |
| 2095 | throw new SecurityException("Not allowed to access cell info"); |
| 2096 | case DENIED_SOFT: |
| 2097 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2100 | final int targetSdk = getTargetSdk(callingPackage); |
| 2101 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2102 | return getCachedCellInfo(); |
| 2103 | } |
| 2104 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2105 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2106 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2107 | final long identity = Binder.clearCallingIdentity(); |
| 2108 | try { |
| 2109 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2110 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2111 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2112 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2113 | if (info != null) cellInfos.addAll(info); |
| 2114 | } |
| 2115 | return cellInfos; |
| 2116 | } finally { |
| 2117 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2121 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2122 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2123 | requestCellInfoUpdateInternal( |
| 2124 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2125 | } |
| 2126 | |
| 2127 | @Override |
| 2128 | public void requestCellInfoUpdateWithWorkSource( |
| 2129 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2130 | enforceModifyPermission(); |
| 2131 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2132 | } |
| 2133 | |
| 2134 | private void requestCellInfoUpdateInternal( |
| 2135 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2136 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2137 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2138 | |
| 2139 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2140 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2141 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2142 | .setCallingPackage(callingPackage) |
| 2143 | .setCallingPid(Binder.getCallingPid()) |
| 2144 | .setCallingUid(Binder.getCallingUid()) |
| 2145 | .setMethod("requestCellInfoUpdate") |
| 2146 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2147 | .build()); |
| 2148 | switch (locationResult) { |
| 2149 | case DENIED_HARD: |
| 2150 | throw new SecurityException("Not allowed to access cell info"); |
| 2151 | case DENIED_SOFT: |
Nathan Harold | b3c5da4 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2152 | try { |
| 2153 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2154 | } catch (RemoteException re) { |
| 2155 | // Drop without consequences |
| 2156 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2157 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Nathan Harold | 32e84c4 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2160 | |
| 2161 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2162 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2163 | |
| 2164 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2165 | } |
| 2166 | |
| 2167 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2168 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2169 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2170 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2171 | |
| 2172 | final long identity = Binder.clearCallingIdentity(); |
| 2173 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2174 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2175 | } finally { |
| 2176 | Binder.restoreCallingIdentity(identity); |
| 2177 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2180 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2181 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2182 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2183 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2184 | return null; |
| 2185 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2186 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2187 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2188 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2189 | return null; |
| 2190 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2191 | |
| 2192 | final long identity = Binder.clearCallingIdentity(); |
| 2193 | try { |
| 2194 | return phone.getImei(); |
| 2195 | } finally { |
| 2196 | Binder.restoreCallingIdentity(identity); |
| 2197 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2201 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2202 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2203 | String tac = null; |
| 2204 | if (phone != null) { |
| 2205 | String imei = phone.getImei(); |
| 2206 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2207 | } |
| 2208 | return tac; |
| 2209 | } |
| 2210 | |
| 2211 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2212 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2213 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2214 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2215 | return null; |
| 2216 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2217 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2218 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2219 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2220 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2221 | return null; |
| 2222 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2223 | |
| 2224 | final long identity = Binder.clearCallingIdentity(); |
| 2225 | try { |
| 2226 | return phone.getMeid(); |
| 2227 | } finally { |
| 2228 | Binder.restoreCallingIdentity(identity); |
| 2229 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2233 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2234 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2235 | String manufacturerCode = null; |
| 2236 | if (phone != null) { |
| 2237 | String meid = phone.getMeid(); |
| 2238 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2239 | } |
| 2240 | return manufacturerCode; |
| 2241 | } |
| 2242 | |
| 2243 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2244 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2245 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2246 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2247 | return null; |
| 2248 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2249 | int subId = phone.getSubId(); |
| 2250 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2251 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2252 | return null; |
| 2253 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2254 | |
| 2255 | final long identity = Binder.clearCallingIdentity(); |
| 2256 | try { |
| 2257 | return phone.getDeviceSvn(); |
| 2258 | } finally { |
| 2259 | Binder.restoreCallingIdentity(identity); |
| 2260 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2263 | @Override |
| 2264 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2265 | final long identity = Binder.clearCallingIdentity(); |
| 2266 | try { |
| 2267 | final Phone phone = getPhone(subId); |
| 2268 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2269 | } finally { |
| 2270 | Binder.restoreCallingIdentity(identity); |
| 2271 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | @Override |
| 2275 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2276 | final long identity = Binder.clearCallingIdentity(); |
| 2277 | try { |
| 2278 | final Phone phone = getPhone(subId); |
| 2279 | return phone == null ? null : phone.getCarrierName(); |
| 2280 | } finally { |
| 2281 | Binder.restoreCallingIdentity(identity); |
| 2282 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2283 | } |
| 2284 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2285 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2286 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2287 | final long identity = Binder.clearCallingIdentity(); |
| 2288 | try { |
| 2289 | final Phone phone = getPhone(subId); |
| 2290 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2291 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2292 | } finally { |
| 2293 | Binder.restoreCallingIdentity(identity); |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2298 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2299 | final long identity = Binder.clearCallingIdentity(); |
| 2300 | try { |
| 2301 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2302 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2303 | } finally { |
| 2304 | Binder.restoreCallingIdentity(identity); |
| 2305 | } |
| 2306 | } |
| 2307 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2308 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2309 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2310 | if (!isSubscriptionMccMnc) { |
| 2311 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2312 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2313 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2314 | if (phone == null) { |
| 2315 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2316 | } |
| 2317 | final long identity = Binder.clearCallingIdentity(); |
| 2318 | try { |
| 2319 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2320 | } finally { |
| 2321 | Binder.restoreCallingIdentity(identity); |
| 2322 | } |
| 2323 | } |
| 2324 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2325 | // |
| 2326 | // Internal helper methods. |
| 2327 | // |
| 2328 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2329 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2330 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2331 | * |
| 2332 | * @throws SecurityException if the caller does not have the required permission |
| 2333 | */ |
| 2334 | private void enforceModifyPermission() { |
| 2335 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2336 | } |
| 2337 | |
| 2338 | /** |
| 2339 | * Make sure the caller has the CALL_PHONE permission. |
| 2340 | * |
| 2341 | * @throws SecurityException if the caller does not have the required permission |
| 2342 | */ |
| 2343 | private void enforceCallPermission() { |
| 2344 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2345 | } |
| 2346 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2347 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2348 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2349 | "ConnectivityService"); |
| 2350 | } |
| 2351 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | private String createTelUrl(String number) { |
| 2353 | if (TextUtils.isEmpty(number)) { |
| 2354 | return null; |
| 2355 | } |
| 2356 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2357 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2360 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2361 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2362 | } |
| 2363 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2364 | private static void logv(String msg) { |
| 2365 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2366 | } |
| 2367 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2368 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2369 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2370 | } |
| 2371 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2372 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2374 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2375 | } |
| 2376 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2377 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2378 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2379 | final long identity = Binder.clearCallingIdentity(); |
| 2380 | try { |
| 2381 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2382 | if (phone == null) { |
| 2383 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2384 | } else { |
| 2385 | return phone.getPhoneType(); |
| 2386 | } |
| 2387 | } finally { |
| 2388 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2389 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | /** |
| 2393 | * Returns the CDMA ERI icon index to display |
| 2394 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2395 | @Override |
| 2396 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2397 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2400 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2401 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2402 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2403 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2404 | return -1; |
| 2405 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2406 | |
| 2407 | final long identity = Binder.clearCallingIdentity(); |
| 2408 | try { |
| 2409 | final Phone phone = getPhone(subId); |
| 2410 | if (phone != null) { |
| 2411 | return phone.getCdmaEriIconIndex(); |
| 2412 | } else { |
| 2413 | return -1; |
| 2414 | } |
| 2415 | } finally { |
| 2416 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2417 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | /** |
| 2421 | * Returns the CDMA ERI icon mode, |
| 2422 | * 0 - ON |
| 2423 | * 1 - FLASHING |
| 2424 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2425 | @Override |
| 2426 | public int getCdmaEriIconMode(String callingPackage) { |
| 2427 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2430 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2431 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2432 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2433 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2434 | return -1; |
| 2435 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2436 | |
| 2437 | final long identity = Binder.clearCallingIdentity(); |
| 2438 | try { |
| 2439 | final Phone phone = getPhone(subId); |
| 2440 | if (phone != null) { |
| 2441 | return phone.getCdmaEriIconMode(); |
| 2442 | } else { |
| 2443 | return -1; |
| 2444 | } |
| 2445 | } finally { |
| 2446 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2447 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | /** |
| 2451 | * Returns the CDMA ERI text, |
| 2452 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2453 | @Override |
| 2454 | public String getCdmaEriText(String callingPackage) { |
| 2455 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2458 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2459 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2461 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2462 | return null; |
| 2463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2464 | |
| 2465 | final long identity = Binder.clearCallingIdentity(); |
| 2466 | try { |
| 2467 | final Phone phone = getPhone(subId); |
| 2468 | if (phone != null) { |
| 2469 | return phone.getCdmaEriText(); |
| 2470 | } else { |
| 2471 | return null; |
| 2472 | } |
| 2473 | } finally { |
| 2474 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2475 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2479 | * Returns the CDMA MDN. |
| 2480 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2481 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2482 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2483 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2484 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2485 | |
| 2486 | final long identity = Binder.clearCallingIdentity(); |
| 2487 | try { |
| 2488 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2489 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2490 | return phone.getLine1Number(); |
| 2491 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2492 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | return null; |
| 2494 | } |
| 2495 | } finally { |
| 2496 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | /** |
| 2501 | * Returns the CDMA MIN. |
| 2502 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2503 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2504 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2505 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2506 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | |
| 2508 | final long identity = Binder.clearCallingIdentity(); |
| 2509 | try { |
| 2510 | final Phone phone = getPhone(subId); |
| 2511 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2512 | return phone.getCdmaMin(); |
| 2513 | } else { |
| 2514 | return null; |
| 2515 | } |
| 2516 | } finally { |
| 2517 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2518 | } |
| 2519 | } |
| 2520 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2521 | @Override |
| 2522 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2523 | INumberVerificationCallback callback, String callingPackage) { |
| 2524 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2525 | != PERMISSION_GRANTED) { |
| 2526 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2527 | } |
| 2528 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2529 | |
| 2530 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2531 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2532 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2533 | } |
| 2534 | |
| 2535 | if (range == null) { |
| 2536 | throw new NullPointerException("Range must be non-null"); |
| 2537 | } |
| 2538 | |
| 2539 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2540 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2541 | |
| 2542 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2543 | } |
| 2544 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2545 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 | * Returns true if CDMA provisioning needs to run. |
| 2547 | */ |
| 2548 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2549 | final long identity = Binder.clearCallingIdentity(); |
| 2550 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2551 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2552 | } finally { |
| 2553 | Binder.restoreCallingIdentity(identity); |
| 2554 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2558 | * Sets the voice mail number of a given subId. |
| 2559 | */ |
| 2560 | @Override |
| 2561 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2562 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2563 | |
| 2564 | final long identity = Binder.clearCallingIdentity(); |
| 2565 | try { |
| 2566 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2567 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2568 | return success; |
| 2569 | } finally { |
| 2570 | Binder.restoreCallingIdentity(identity); |
| 2571 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2572 | } |
| 2573 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2574 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2575 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2576 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2577 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2578 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2579 | throw new SecurityException("caller must be system dialer"); |
| 2580 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2581 | |
| 2582 | final long identity = Binder.clearCallingIdentity(); |
| 2583 | try { |
| 2584 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2585 | if (phoneAccountHandle == null) { |
| 2586 | return null; |
| 2587 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2588 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2591 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2595 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2596 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2597 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2598 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2599 | return null; |
| 2600 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2601 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2602 | final long identity = Binder.clearCallingIdentity(); |
| 2603 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2604 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2605 | } finally { |
| 2606 | Binder.restoreCallingIdentity(identity); |
| 2607 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2611 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2612 | VisualVoicemailSmsFilterSettings settings) { |
| 2613 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | |
| 2615 | final long identity = Binder.clearCallingIdentity(); |
| 2616 | try { |
| 2617 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2618 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
| 2621 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2625 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2626 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | |
| 2628 | final long identity = Binder.clearCallingIdentity(); |
| 2629 | try { |
| 2630 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2631 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2632 | } finally { |
| 2633 | Binder.restoreCallingIdentity(identity); |
| 2634 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2638 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2639 | String callingPackage, int subId) { |
| 2640 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | |
| 2642 | final long identity = Binder.clearCallingIdentity(); |
| 2643 | try { |
| 2644 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2645 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | } finally { |
| 2647 | Binder.restoreCallingIdentity(identity); |
| 2648 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2652 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2653 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | |
| 2655 | final long identity = Binder.clearCallingIdentity(); |
| 2656 | try { |
| 2657 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2658 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | } finally { |
| 2660 | Binder.restoreCallingIdentity(identity); |
| 2661 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | @Override |
| 2665 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2666 | String number, int port, String text, PendingIntent sentIntent) { |
| 2667 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2668 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2669 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2670 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2671 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2672 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2673 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2674 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2675 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2676 | * Sets the voice activation state of a given subId. |
| 2677 | */ |
| 2678 | @Override |
| 2679 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2681 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2682 | |
| 2683 | final long identity = Binder.clearCallingIdentity(); |
| 2684 | try { |
| 2685 | final Phone phone = getPhone(subId); |
| 2686 | if (phone != null) { |
| 2687 | phone.setVoiceActivationState(activationState); |
| 2688 | } else { |
| 2689 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2690 | } |
| 2691 | } finally { |
| 2692 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | /** |
| 2697 | * Sets the data activation state of a given subId. |
| 2698 | */ |
| 2699 | @Override |
| 2700 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2701 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2702 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | |
| 2704 | final long identity = Binder.clearCallingIdentity(); |
| 2705 | try { |
| 2706 | final Phone phone = getPhone(subId); |
| 2707 | if (phone != null) { |
| 2708 | phone.setDataActivationState(activationState); |
| 2709 | } else { |
| 2710 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2711 | } |
| 2712 | } finally { |
| 2713 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | /** |
| 2718 | * Returns the voice activation state of a given subId. |
| 2719 | */ |
| 2720 | @Override |
| 2721 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2722 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2723 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2724 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | if (phone != null) { |
| 2728 | return phone.getVoiceActivationState(); |
| 2729 | } else { |
| 2730 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2731 | } |
| 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | /** |
| 2738 | * Returns the data activation state of a given subId. |
| 2739 | */ |
| 2740 | @Override |
| 2741 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2742 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2743 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2744 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2745 | final long identity = Binder.clearCallingIdentity(); |
| 2746 | try { |
| 2747 | if (phone != null) { |
| 2748 | return phone.getDataActivationState(); |
| 2749 | } else { |
| 2750 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2751 | } |
| 2752 | } finally { |
| 2753 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2758 | * Returns the unread count of voicemails for a subId |
| 2759 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2760 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2761 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2762 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2763 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2764 | return 0; |
| 2765 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | final long identity = Binder.clearCallingIdentity(); |
| 2767 | try { |
| 2768 | final Phone phone = getPhone(subId); |
| 2769 | if (phone != null) { |
| 2770 | return phone.getVoiceMessageCount(); |
| 2771 | } else { |
| 2772 | return 0; |
| 2773 | } |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2780 | * returns true, if the device is in a state where both voice and data |
| 2781 | * are supported simultaneously. This can change based on location or network condition. |
| 2782 | */ |
| 2783 | @Override |
| 2784 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2785 | final long identity = Binder.clearCallingIdentity(); |
| 2786 | try { |
| 2787 | final Phone phone = getPhone(subId); |
| 2788 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2789 | } finally { |
| 2790 | Binder.restoreCallingIdentity(identity); |
| 2791 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2795 | * Send the dialer code if called from the current default dialer or the caller has |
| 2796 | * carrier privilege. |
| 2797 | * @param inputCode The dialer code to send |
| 2798 | */ |
| 2799 | @Override |
| 2800 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2801 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2802 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2803 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2804 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2805 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2806 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2807 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2808 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2809 | |
| 2810 | final long identity = Binder.clearCallingIdentity(); |
| 2811 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2812 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2813 | } finally { |
| 2814 | Binder.restoreCallingIdentity(identity); |
| 2815 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2816 | } |
| 2817 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2818 | @Override |
| 2819 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2820 | if (!isActiveSubscription(subId)) { |
| 2821 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2822 | } |
| 2823 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2824 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2825 | } |
| 2826 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2827 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2828 | public boolean isInEmergencySmsMode() { |
| 2829 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2830 | final long identity = Binder.clearCallingIdentity(); |
| 2831 | try { |
| 2832 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2833 | if (phone.isInEmergencySmsMode()) { |
| 2834 | return true; |
| 2835 | } |
| 2836 | } |
| 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(identity); |
| 2839 | } |
| 2840 | return false; |
| 2841 | } |
| 2842 | |
| 2843 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2844 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2845 | throws RemoteException { |
| 2846 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2847 | final long token = Binder.clearCallingIdentity(); |
| 2848 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2849 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2850 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2851 | .addRegistrationCallbackForSubscription(c, subId); |
| 2852 | } finally { |
| 2853 | Binder.restoreCallingIdentity(token); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2858 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2859 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2860 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2861 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2862 | } |
| 2863 | Binder.withCleanCallingIdentity(() -> { |
| 2864 | try { |
| 2865 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2866 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2867 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2868 | } catch (IllegalArgumentException e) { |
| 2869 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2870 | + "is inactive, ignoring unregister."); |
| 2871 | // If the subscription is no longer active, just return, since the callback |
| 2872 | // will already have been removed internally. |
| 2873 | } |
| 2874 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2878 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2879 | throws RemoteException { |
| 2880 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2881 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2882 | final long token = Binder.clearCallingIdentity(); |
| 2883 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2884 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2885 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2886 | } finally { |
| 2887 | Binder.restoreCallingIdentity(token); |
| 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2892 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2893 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2894 | |
| 2895 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2896 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2897 | } |
| 2898 | Binder.withCleanCallingIdentity(() -> { |
| 2899 | try { |
| 2900 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2901 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2902 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2903 | } catch (IllegalArgumentException e) { |
| 2904 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2905 | + "is inactive, ignoring unregister."); |
| 2906 | // If the subscription is no longer active, just return, since the callback |
| 2907 | // will already have been removed internally. |
| 2908 | } |
| 2909 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2913 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2914 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2915 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2916 | final long token = Binder.clearCallingIdentity(); |
| 2917 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2918 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2919 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2920 | } catch (ImsException e) { |
| 2921 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2922 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2923 | } catch (IllegalArgumentException e) { |
| 2924 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2925 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2926 | } finally { |
| 2927 | Binder.restoreCallingIdentity(token); |
| 2928 | } |
| 2929 | } |
| 2930 | |
| 2931 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2932 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2933 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2934 | final long token = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | Phone phone = getPhone(subId); |
| 2937 | if (phone == null) return false; |
| 2938 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(token); |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | @Override |
| 2945 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2946 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2947 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2948 | final long token = Binder.clearCallingIdentity(); |
| 2949 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2950 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2951 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2952 | } finally { |
| 2953 | Binder.restoreCallingIdentity(token); |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2958 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2960 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2961 | final long identity = Binder.clearCallingIdentity(); |
| 2962 | try { |
| 2963 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2964 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2965 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2966 | } finally { |
| 2967 | Binder.restoreCallingIdentity(identity); |
| 2968 | } |
| 2969 | } |
| 2970 | |
| 2971 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2972 | public boolean isVtSettingEnabled(int subId) { |
| 2973 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2974 | final long identity = Binder.clearCallingIdentity(); |
| 2975 | try { |
| 2976 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2977 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2978 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2979 | } finally { |
| 2980 | Binder.restoreCallingIdentity(identity); |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2985 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2987 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2988 | final long identity = Binder.clearCallingIdentity(); |
| 2989 | try { |
| 2990 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2991 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2992 | } finally { |
| 2993 | Binder.restoreCallingIdentity(identity); |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | @Override |
| 2998 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2999 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3000 | final long identity = Binder.clearCallingIdentity(); |
| 3001 | try { |
| 3002 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3003 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3004 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3011 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3013 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3014 | final long identity = Binder.clearCallingIdentity(); |
| 3015 | try { |
| 3016 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3017 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
| 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | @Override |
| 3024 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3025 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3026 | final long identity = Binder.clearCallingIdentity(); |
| 3027 | try { |
| 3028 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3029 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3030 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3031 | } finally { |
| 3032 | Binder.restoreCallingIdentity(identity); |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3037 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3039 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3040 | final long identity = Binder.clearCallingIdentity(); |
| 3041 | try { |
| 3042 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3043 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3044 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3045 | } finally { |
| 3046 | Binder.restoreCallingIdentity(identity); |
| 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | @Override |
| 3051 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3052 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3053 | "setVoWiFiNonPersistent"); |
| 3054 | final long identity = Binder.clearCallingIdentity(); |
| 3055 | try { |
| 3056 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3057 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3058 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3059 | } finally { |
| 3060 | Binder.restoreCallingIdentity(identity); |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | @Override |
| 3065 | public int getVoWiFiModeSetting(int subId) { |
| 3066 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3067 | final long identity = Binder.clearCallingIdentity(); |
| 3068 | try { |
| 3069 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3070 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3071 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3072 | } finally { |
| 3073 | Binder.restoreCallingIdentity(identity); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | @Override |
| 3078 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3079 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3080 | "setVoWiFiModeSetting"); |
| 3081 | final long identity = Binder.clearCallingIdentity(); |
| 3082 | try { |
| 3083 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3084 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3085 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3086 | } finally { |
| 3087 | Binder.restoreCallingIdentity(identity); |
| 3088 | } |
| 3089 | } |
| 3090 | |
| 3091 | @Override |
| 3092 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3093 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
| 3096 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3097 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3098 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3099 | } finally { |
| 3100 | Binder.restoreCallingIdentity(identity); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | @Override |
| 3105 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3106 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3107 | "setVoWiFiRoamingModeSetting"); |
| 3108 | final long identity = Binder.clearCallingIdentity(); |
| 3109 | try { |
| 3110 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3111 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3112 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3113 | } finally { |
| 3114 | Binder.restoreCallingIdentity(identity); |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | @Override |
| 3119 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3120 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3121 | "setRttCapabilityEnabled"); |
| 3122 | final long identity = Binder.clearCallingIdentity(); |
| 3123 | try { |
| 3124 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3125 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3126 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3127 | } finally { |
| 3128 | Binder.restoreCallingIdentity(identity); |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | @Override |
| 3133 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3134 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3135 | final long identity = Binder.clearCallingIdentity(); |
| 3136 | try { |
| 3137 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3138 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3139 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
| 3142 | } |
| 3143 | } |
| 3144 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3145 | @Override |
| 3146 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3147 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3148 | final long identity = Binder.clearCallingIdentity(); |
| 3149 | try { |
| 3150 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3151 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3152 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(identity); |
| 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | @Override |
| 3159 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3160 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3161 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3162 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3163 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3164 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3165 | try { |
| 3166 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3167 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3168 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3169 | } catch (IllegalArgumentException e) { |
| 3170 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3171 | + "is inactive, ignoring unregister."); |
| 3172 | // If the subscription is no longer active, just return, since the callback will already |
| 3173 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3180 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3181 | boolean isProvisioned) { |
| 3182 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3183 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3184 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3185 | } |
| 3186 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3187 | "setProvisioningStatusForCapability"); |
| 3188 | final long identity = Binder.clearCallingIdentity(); |
| 3189 | try { |
| 3190 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3191 | Phone phone = getPhone(subId); |
| 3192 | if (phone == null) { |
| 3193 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3194 | + subId); |
| 3195 | return; |
| 3196 | } |
| 3197 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3198 | return; |
| 3199 | } |
| 3200 | |
| 3201 | // this capability requires provisioning, route to the correct API. |
| 3202 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3203 | switch (capability) { |
| 3204 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3205 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3206 | ims.setVolteProvisioned(isProvisioned); |
| 3207 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3208 | ims.setWfcProvisioned(isProvisioned); |
| 3209 | } |
| 3210 | break; |
| 3211 | } |
| 3212 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3213 | // There is currently no difference in VT provisioning type. |
| 3214 | ims.setVtProvisioned(isProvisioned); |
| 3215 | break; |
| 3216 | } |
| 3217 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3218 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3219 | // change the capability of the feature instead if needed. |
| 3220 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3221 | == isProvisioned) { |
| 3222 | // No change in provisioning. |
| 3223 | return; |
| 3224 | } |
| 3225 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3226 | try { |
| 3227 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3228 | } catch (ImsException e) { |
| 3229 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3230 | + ", Exception" + e.getMessage()); |
| 3231 | } |
| 3232 | break; |
| 3233 | } |
| 3234 | default: { |
| 3235 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3236 | + capability + "', which does not require provisioning."); |
| 3237 | } |
| 3238 | } |
| 3239 | |
| 3240 | } finally { |
| 3241 | Binder.restoreCallingIdentity(identity); |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | @Override |
| 3246 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3247 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3248 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3249 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3250 | } |
| 3251 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3252 | final long identity = Binder.clearCallingIdentity(); |
| 3253 | try { |
| 3254 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3255 | Phone phone = getPhone(subId); |
| 3256 | if (phone == null) { |
| 3257 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3258 | + subId); |
| 3259 | // We will fail with "true" as the provisioning status because this is the default |
| 3260 | // if we do not require provisioning. |
| 3261 | return true; |
| 3262 | } |
| 3263 | |
| 3264 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3265 | return true; |
| 3266 | } |
| 3267 | |
| 3268 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3269 | switch (capability) { |
| 3270 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3271 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3272 | return ims.isVolteProvisionedOnDevice(); |
| 3273 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3274 | return ims.isWfcProvisionedOnDevice(); |
| 3275 | } |
| 3276 | // This should never happen, since we are checking tech above to make sure it |
| 3277 | // is either LTE or IWLAN. |
| 3278 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3279 | + "capability."); |
| 3280 | } |
| 3281 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3282 | // There is currently no difference in VT provisioning type. |
| 3283 | return ims.isVtProvisionedOnDevice(); |
| 3284 | } |
| 3285 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3286 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3287 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3288 | } |
| 3289 | default: { |
| 3290 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3291 | + capability + "', which does not require provisioning."); |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | } finally { |
| 3296 | Binder.restoreCallingIdentity(identity); |
| 3297 | } |
| 3298 | } |
| 3299 | |
| 3300 | @Override |
| 3301 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3302 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3303 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3304 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3305 | } |
| 3306 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3307 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3308 | return (provisionedBits & capability) > 0; |
| 3309 | } |
| 3310 | |
| 3311 | @Override |
| 3312 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3313 | boolean isProvisioned) { |
| 3314 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3315 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3316 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3317 | } |
| 3318 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3319 | "setProvisioningStatusForCapability"); |
| 3320 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3321 | // If the current provisioning status for capability already matches isProvisioned, |
| 3322 | // do nothing. |
| 3323 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3324 | return; |
| 3325 | } |
| 3326 | if (isProvisioned) { |
| 3327 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3328 | } else { |
| 3329 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3330 | } |
| 3331 | } |
| 3332 | |
| 3333 | /** |
| 3334 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3335 | * technology. The bitfield should mirror the bitfield defined by |
| 3336 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3337 | */ |
| 3338 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3339 | String key = getMmTelProvisioningKey(subId, tech); |
| 3340 | // Default is no capabilities are provisioned. |
| 3341 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3342 | } |
| 3343 | |
| 3344 | /** |
| 3345 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3346 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3347 | * technology specified. |
| 3348 | * |
| 3349 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3350 | */ |
| 3351 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3352 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3353 | String key = getMmTelProvisioningKey(subId, tech); |
| 3354 | editor.putInt(key, newField); |
| 3355 | editor.commit(); |
| 3356 | } |
| 3357 | |
| 3358 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3359 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3360 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3361 | } |
| 3362 | |
| 3363 | /** |
| 3364 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3365 | * carrier associated with the subscription id. |
| 3366 | */ |
| 3367 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3368 | int capability) { |
| 3369 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3370 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3371 | boolean requireUtProvisioning = c.getBoolean( |
| 3372 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3373 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3374 | // the no-SIM case, where we would normally shortcut this to false. |
| 3375 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3376 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3377 | false); |
| 3378 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3379 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3380 | |
| 3381 | // First check to make sure that the capability requires provisioning. |
| 3382 | switch (capability) { |
| 3383 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3384 | // intentional fallthrough |
| 3385 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3386 | if (requireVoiceVtProvisioning) { |
| 3387 | // Voice and Video requires provisioning |
| 3388 | return true; |
| 3389 | } |
| 3390 | break; |
| 3391 | } |
| 3392 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3393 | if (requireUtProvisioning) { |
| 3394 | // UT requires provisioning |
| 3395 | return true; |
| 3396 | } |
| 3397 | break; |
| 3398 | } |
| 3399 | } |
| 3400 | return false; |
| 3401 | } |
| 3402 | |
| 3403 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3404 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3405 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3406 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3407 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3408 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3409 | final long identity = Binder.clearCallingIdentity(); |
| 3410 | try { |
| 3411 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3412 | int slotId = getSlotIndex(subId); |
| 3413 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3414 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3415 | + subId + "' for key:" + key); |
| 3416 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3417 | } |
| 3418 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3419 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3420 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3421 | + subId + "' for key:" + key); |
| 3422 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3423 | } finally { |
| 3424 | Binder.restoreCallingIdentity(identity); |
| 3425 | } |
| 3426 | } |
| 3427 | |
| 3428 | @Override |
| 3429 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3430 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3431 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3432 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3433 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3434 | final long identity = Binder.clearCallingIdentity(); |
| 3435 | try { |
| 3436 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3437 | int slotId = getSlotIndex(subId); |
| 3438 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3439 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3440 | + subId + "' for key:" + key); |
| 3441 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3442 | } |
| 3443 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3444 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3445 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3446 | + subId + "' for key:" + key); |
| 3447 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3448 | } finally { |
| 3449 | Binder.restoreCallingIdentity(identity); |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | @Override |
| 3454 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3455 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3456 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3457 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3458 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3459 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3460 | final long identity = Binder.clearCallingIdentity(); |
| 3461 | try { |
| 3462 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3463 | int slotId = getSlotIndex(subId); |
| 3464 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3465 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3466 | + subId + "' for key:" + key); |
| 3467 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3468 | } |
| 3469 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3470 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3471 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3472 | + "' for key:" + key); |
| 3473 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3474 | } finally { |
| 3475 | Binder.restoreCallingIdentity(identity); |
| 3476 | } |
| 3477 | } |
| 3478 | |
| 3479 | @Override |
| 3480 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3481 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3482 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3483 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3484 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3485 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3486 | final long identity = Binder.clearCallingIdentity(); |
| 3487 | try { |
| 3488 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3489 | int slotId = getSlotIndex(subId); |
| 3490 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3491 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3492 | + subId + "' for key:" + key); |
| 3493 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3494 | } |
| 3495 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3496 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3497 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3498 | + "' for key:" + key); |
| 3499 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3500 | } finally { |
| 3501 | Binder.restoreCallingIdentity(identity); |
| 3502 | } |
| 3503 | } |
| 3504 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3505 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3506 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3507 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3508 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3509 | } |
| 3510 | return slotId; |
| 3511 | } |
| 3512 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3513 | private int getSlotIndex(int subId) { |
| 3514 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3515 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3516 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3517 | } |
| 3518 | return slotId; |
| 3519 | } |
| 3520 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3521 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3522 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3523 | */ |
| 3524 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3525 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3526 | if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q |
| 3527 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
| 3528 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3529 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3530 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3531 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3532 | final long identity = Binder.clearCallingIdentity(); |
| 3533 | try { |
| 3534 | final Phone phone = getPhone(subId); |
| 3535 | if (phone != null) { |
| 3536 | return phone.getServiceState().getDataNetworkType(); |
| 3537 | } else { |
| 3538 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3539 | } |
| 3540 | } finally { |
| 3541 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3542 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | /** |
| 3546 | * Returns the data network type |
| 3547 | */ |
| 3548 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3549 | public int getDataNetworkType(String callingPackage) { |
| 3550 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | /** |
| 3554 | * Returns the data network type for a subId |
| 3555 | */ |
| 3556 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3557 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3558 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3559 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3560 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3561 | } |
| 3562 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3563 | final long identity = Binder.clearCallingIdentity(); |
| 3564 | try { |
| 3565 | final Phone phone = getPhone(subId); |
| 3566 | if (phone != null) { |
| 3567 | return phone.getServiceState().getDataNetworkType(); |
| 3568 | } else { |
| 3569 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3570 | } |
| 3571 | } finally { |
| 3572 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3573 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
| 3576 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3577 | * Returns the Voice network type for a subId |
| 3578 | */ |
| 3579 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3580 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3581 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3582 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3583 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3584 | } |
| 3585 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3586 | final long identity = Binder.clearCallingIdentity(); |
| 3587 | try { |
| 3588 | final Phone phone = getPhone(subId); |
| 3589 | if (phone != null) { |
| 3590 | return phone.getServiceState().getVoiceNetworkType(); |
| 3591 | } else { |
| 3592 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3593 | } |
| 3594 | } finally { |
| 3595 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3596 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | /** |
| 3600 | * @return true if a ICC card is present |
| 3601 | */ |
| 3602 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3603 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3604 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3605 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
| 3608 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3609 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3610 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3611 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3612 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3613 | final long identity = Binder.clearCallingIdentity(); |
| 3614 | try { |
| 3615 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3616 | if (phone != null) { |
| 3617 | return phone.getIccCard().hasIccCard(); |
| 3618 | } else { |
| 3619 | return false; |
| 3620 | } |
| 3621 | } finally { |
| 3622 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3623 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | /** |
| 3627 | * Return if the current radio is LTE on CDMA. This |
| 3628 | * is a tri-state return value as for a period of time |
| 3629 | * the mode may be unknown. |
| 3630 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3631 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3632 | * @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] | 3633 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3634 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3635 | @Override |
| 3636 | public int getLteOnCdmaMode(String callingPackage) { |
| 3637 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3640 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3641 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3642 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3643 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3644 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3645 | } |
| 3646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3647 | final long identity = Binder.clearCallingIdentity(); |
| 3648 | try { |
| 3649 | final Phone phone = getPhone(subId); |
| 3650 | if (phone == null) { |
| 3651 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3652 | } else { |
| 3653 | return phone.getLteOnCdmaMode(); |
| 3654 | } |
| 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3657 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3660 | /** |
| 3661 | * {@hide} |
| 3662 | * Returns Default subId, 0 in the case of single standby. |
| 3663 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3664 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3665 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3668 | private int getSlotForDefaultSubscription() { |
| 3669 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3670 | } |
| 3671 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3672 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3673 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3674 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3675 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3676 | private boolean isActiveSubscription(int subId) { |
| 3677 | return mSubscriptionController.isActiveSubId(subId); |
| 3678 | } |
| 3679 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3680 | /** |
| 3681 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3682 | */ |
| 3683 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3684 | final long identity = Binder.clearCallingIdentity(); |
| 3685 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3686 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3687 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3688 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(identity); |
| 3691 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | /** |
| 3695 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3696 | */ |
| 3697 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3701 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3702 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3703 | } finally { |
| 3704 | Binder.restoreCallingIdentity(identity); |
| 3705 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3706 | } |
| 3707 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3708 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3709 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3710 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3711 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3712 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3713 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3714 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3715 | if (phoneId == -1) { |
| 3716 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3717 | + " does not correspond to an active phone"); |
| 3718 | } |
| 3719 | return PhoneFactory.getPhone(phoneId); |
| 3720 | } |
| 3721 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3722 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3723 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3724 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3725 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3726 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3727 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3728 | if (DBG) { |
| 3729 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3730 | } |
| 3731 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3732 | p2); |
| 3733 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3734 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3735 | |
| 3736 | @Override |
| 3737 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3738 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3739 | enforceModifyPermission(); |
| 3740 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3741 | if (DBG) { |
| 3742 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3743 | } |
| 3744 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3745 | callingPackage, aid, p2); |
| 3746 | } |
| 3747 | |
| 3748 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3749 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | final long identity = Binder.clearCallingIdentity(); |
| 3751 | try { |
| 3752 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3753 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3754 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3755 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3756 | if (bestComponent == null |
| 3757 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3758 | loge("The calling package is not allowed to access ISD-R."); |
| 3759 | throw new SecurityException( |
| 3760 | "The calling package is not allowed to access ISD-R."); |
| 3761 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3762 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3763 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3764 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3765 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3766 | null /* workSource */); |
| 3767 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | return response; |
| 3769 | } finally { |
| 3770 | Binder.restoreCallingIdentity(identity); |
| 3771 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3775 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3776 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3777 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3778 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3779 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3780 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3781 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3782 | @Override |
| 3783 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3784 | enforceModifyPermission(); |
| 3785 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3786 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3787 | channel); |
| 3788 | } |
| 3789 | |
| 3790 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3791 | final long identity = Binder.clearCallingIdentity(); |
| 3792 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3793 | if (channel < 0) { |
| 3794 | return false; |
| 3795 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3796 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3797 | null /* workSource */); |
| 3798 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3799 | return success; |
| 3800 | } finally { |
| 3801 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3802 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3806 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3807 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3808 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3809 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3810 | if (DBG) { |
| 3811 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3812 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3813 | + p3 + " data=" + data); |
| 3814 | } |
| 3815 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3816 | command, p1, p2, p3, data); |
| 3817 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3818 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3819 | @Override |
| 3820 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3821 | int command, int p1, int p2, int p3, String data) { |
| 3822 | enforceModifyPermission(); |
| 3823 | if (DBG) { |
| 3824 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3825 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3826 | + p3 + " data=" + data); |
| 3827 | } |
| 3828 | return iccTransmitApduLogicalChannelWithPermission( |
| 3829 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3830 | data); |
| 3831 | } |
| 3832 | |
| 3833 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3834 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3835 | final long identity = Binder.clearCallingIdentity(); |
| 3836 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 3837 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3838 | return ""; |
| 3839 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3840 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3841 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3842 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3843 | null /* workSource */); |
| 3844 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3845 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3846 | // Append the returned status code to the end of the response payload. |
| 3847 | String s = Integer.toHexString( |
| 3848 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3849 | if (response.payload != null) { |
| 3850 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3851 | } |
| 3852 | return s; |
| 3853 | } finally { |
| 3854 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3855 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3856 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3857 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3858 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3859 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3860 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3861 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3862 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3864 | if (DBG) { |
| 3865 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3866 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3867 | } |
| 3868 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3869 | cla, command, p1, p2, p3, data); |
| 3870 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3871 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3872 | @Override |
| 3873 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3874 | int command, int p1, int p2, int p3, String data) { |
| 3875 | enforceModifyPermission(); |
| 3876 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3877 | if (DBG) { |
| 3878 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3879 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3880 | + " data=" + data); |
| 3881 | } |
| 3882 | |
| 3883 | return iccTransmitApduBasicChannelWithPermission( |
| 3884 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3885 | p2, p3, data); |
| 3886 | } |
| 3887 | |
| 3888 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3889 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3890 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3891 | final long identity = Binder.clearCallingIdentity(); |
| 3892 | try { |
| 3893 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3894 | && TextUtils.equals(ISDR_AID, data)) { |
| 3895 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3896 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3897 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3898 | if (bestComponent == null |
| 3899 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3900 | loge("The calling package is not allowed to select ISD-R."); |
| 3901 | throw new SecurityException( |
| 3902 | "The calling package is not allowed to select ISD-R."); |
| 3903 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3904 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3905 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3906 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3907 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3908 | null /* workSource */); |
| 3909 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3910 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 | // Append the returned status code to the end of the response payload. |
| 3912 | String s = Integer.toHexString( |
| 3913 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3914 | if (response.payload != null) { |
| 3915 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3916 | } |
| 3917 | return s; |
| 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3920 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3924 | 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] | 3925 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3926 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3927 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3928 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3929 | final long identity = Binder.clearCallingIdentity(); |
| 3930 | try { |
| 3931 | if (DBG) { |
| 3932 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3933 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3934 | } |
| 3935 | |
| 3936 | IccIoResult response = |
| 3937 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3938 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3939 | subId); |
| 3940 | |
| 3941 | if (DBG) { |
| 3942 | log("Exchange SIM_IO [R]" + response); |
| 3943 | } |
| 3944 | |
| 3945 | byte[] result = null; |
| 3946 | int length = 2; |
| 3947 | if (response.payload != null) { |
| 3948 | length = 2 + response.payload.length; |
| 3949 | result = new byte[length]; |
| 3950 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3951 | } else { |
| 3952 | result = new byte[length]; |
| 3953 | } |
| 3954 | |
| 3955 | result[length - 1] = (byte) response.sw2; |
| 3956 | result[length - 2] = (byte) response.sw1; |
| 3957 | return result; |
| 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3960 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3963 | /** |
| 3964 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3965 | * on a particular subscription |
| 3966 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3967 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3968 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3969 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3970 | return null; |
| 3971 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3972 | |
| 3973 | final long identity = Binder.clearCallingIdentity(); |
| 3974 | try { |
| 3975 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3976 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3977 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3978 | return null; |
| 3979 | } |
| 3980 | Object response = sendRequest( |
| 3981 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3982 | if (response instanceof String[]) { |
| 3983 | return (String[]) response; |
| 3984 | } |
| 3985 | // Response is an Exception of some kind, |
| 3986 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3987 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3988 | } finally { |
| 3989 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3990 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3991 | } |
| 3992 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3993 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3994 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3995 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3996 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3997 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3998 | final long identity = Binder.clearCallingIdentity(); |
| 3999 | try { |
| 4000 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4001 | if (response.payload == null) { |
| 4002 | return ""; |
| 4003 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4004 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4005 | // Append the returned status code to the end of the response payload. |
| 4006 | String s = Integer.toHexString( |
| 4007 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4008 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4009 | return s; |
| 4010 | } finally { |
| 4011 | Binder.restoreCallingIdentity(identity); |
| 4012 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4013 | } |
| 4014 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4015 | /** |
| 4016 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4017 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4018 | * |
| 4019 | * @param itemID the ID of the item to read |
| 4020 | * @return the NV item as a String, or null on error. |
| 4021 | */ |
| 4022 | @Override |
| 4023 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4024 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4026 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4027 | |
| 4028 | final long identity = Binder.clearCallingIdentity(); |
| 4029 | try { |
| 4030 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4031 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4032 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4033 | return value; |
| 4034 | } finally { |
| 4035 | Binder.restoreCallingIdentity(identity); |
| 4036 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | /** |
| 4040 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4041 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4042 | * |
| 4043 | * @param itemID the ID of the item to read |
| 4044 | * @param itemValue the value to write, as a String |
| 4045 | * @return true on success; false on any failure |
| 4046 | */ |
| 4047 | @Override |
| 4048 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4049 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4050 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4051 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4052 | |
| 4053 | final long identity = Binder.clearCallingIdentity(); |
| 4054 | try { |
| 4055 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4056 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4057 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4058 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4059 | return success; |
| 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(identity); |
| 4062 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | /** |
| 4066 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4067 | * Used for device configuration by some CDMA operators. |
| 4068 | * |
| 4069 | * @param preferredRoamingList byte array containing the new PRL |
| 4070 | * @return true on success; false on any failure |
| 4071 | */ |
| 4072 | @Override |
| 4073 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4075 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4076 | |
| 4077 | final long identity = Binder.clearCallingIdentity(); |
| 4078 | try { |
| 4079 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4080 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4081 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4082 | return success; |
| 4083 | } finally { |
| 4084 | Binder.restoreCallingIdentity(identity); |
| 4085 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4089 | * 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] | 4090 | * Used for device configuration by some CDMA operators. |
| 4091 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4092 | * @param slotIndex - device slot. |
| 4093 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4094 | * @return true on success; false on any failure |
| 4095 | */ |
| 4096 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4097 | public boolean resetModemConfig(int slotIndex) { |
| 4098 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4099 | if (phone != null) { |
| 4100 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4101 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4102 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4103 | final long identity = Binder.clearCallingIdentity(); |
| 4104 | try { |
| 4105 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4106 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4107 | return success; |
| 4108 | } finally { |
| 4109 | Binder.restoreCallingIdentity(identity); |
| 4110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4111 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4112 | return false; |
| 4113 | } |
| 4114 | |
| 4115 | /** |
| 4116 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4117 | * |
| 4118 | * @param slotIndex - device slot. |
| 4119 | * |
| 4120 | * @return true on success; false on any failure |
| 4121 | */ |
| 4122 | @Override |
| 4123 | public boolean rebootModem(int slotIndex) { |
| 4124 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4125 | if (phone != null) { |
| 4126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4127 | mApp, phone.getSubId(), "rebootModem"); |
| 4128 | |
| 4129 | final long identity = Binder.clearCallingIdentity(); |
| 4130 | try { |
| 4131 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4132 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4133 | return success; |
| 4134 | } finally { |
| 4135 | Binder.restoreCallingIdentity(identity); |
| 4136 | } |
| 4137 | } |
| 4138 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4139 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4140 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4141 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4142 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4144 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4145 | return new String[0]; |
| 4146 | } |
| 4147 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | final long identity = Binder.clearCallingIdentity(); |
| 4149 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4150 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4151 | } finally { |
| 4152 | Binder.restoreCallingIdentity(identity); |
| 4153 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4154 | } |
| 4155 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4156 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4157 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4158 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4159 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4160 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4161 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4162 | |
| 4163 | final long identity = Binder.clearCallingIdentity(); |
| 4164 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4165 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4166 | if (resolver == null) { |
| 4167 | // may happen if the device does not support IMS. |
| 4168 | return; |
| 4169 | } |
| 4170 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4171 | } finally { |
| 4172 | Binder.restoreCallingIdentity(identity); |
| 4173 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4177 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4178 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4179 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4180 | public void disableIms(int slotId) { |
| 4181 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4182 | |
| 4183 | final long identity = Binder.clearCallingIdentity(); |
| 4184 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4185 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4186 | if (resolver == null) { |
| 4187 | // may happen if the device does not support IMS. |
| 4188 | return; |
| 4189 | } |
| 4190 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4191 | } finally { |
| 4192 | Binder.restoreCallingIdentity(identity); |
| 4193 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | /** |
| 4197 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4198 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4199 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4200 | */ |
| 4201 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4202 | IImsServiceFeatureCallback callback) { |
| 4203 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4204 | |
| 4205 | final long identity = Binder.clearCallingIdentity(); |
| 4206 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4207 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4208 | if (resolver == null) { |
| 4209 | // may happen if the device does not support IMS. |
| 4210 | return null; |
| 4211 | } |
| 4212 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(identity); |
| 4215 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | /** |
| 4219 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4220 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4221 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4222 | * listener for feature updates. |
| 4223 | */ |
| 4224 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4225 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4226 | |
| 4227 | final long identity = Binder.clearCallingIdentity(); |
| 4228 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4229 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4230 | if (resolver == null) { |
| 4231 | // may happen if the device does not support IMS. |
| 4232 | return null; |
| 4233 | } |
| 4234 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4235 | } finally { |
| 4236 | Binder.restoreCallingIdentity(identity); |
| 4237 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4238 | } |
| 4239 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4240 | /** |
| 4241 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4242 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4243 | */ |
| 4244 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4245 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4246 | |
| 4247 | final long identity = Binder.clearCallingIdentity(); |
| 4248 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4249 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4250 | if (resolver == null) { |
| 4251 | // may happen if the device does not support IMS. |
| 4252 | return null; |
| 4253 | } |
| 4254 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4255 | } finally { |
| 4256 | Binder.restoreCallingIdentity(identity); |
| 4257 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4258 | } |
| 4259 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4260 | /** |
| 4261 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4262 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4263 | */ |
| 4264 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4265 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4266 | |
| 4267 | final long identity = Binder.clearCallingIdentity(); |
| 4268 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4269 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4270 | if (resolver == null) { |
| 4271 | // may happen if the device does not support IMS. |
| 4272 | return null; |
| 4273 | } |
| 4274 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4275 | } finally { |
| 4276 | Binder.restoreCallingIdentity(identity); |
| 4277 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4278 | } |
| 4279 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4280 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4281 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4282 | * |
| 4283 | * @param slotId the slot ID that the ImsService should bind for. |
| 4284 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4285 | * ImsService is the device default ImsService. |
| 4286 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4287 | * to. |
| 4288 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4289 | * @hide |
| 4290 | */ |
| 4291 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4292 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4294 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4295 | "setImsService"); |
| 4296 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4297 | final long identity = Binder.clearCallingIdentity(); |
| 4298 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4299 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4300 | if (resolver == null) { |
| 4301 | // may happen if the device does not support IMS. |
| 4302 | return false; |
| 4303 | } |
| 4304 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4305 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4306 | } finally { |
| 4307 | Binder.restoreCallingIdentity(identity); |
| 4308 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | /** |
| 4312 | * Return the ImsService configuration. |
| 4313 | * |
| 4314 | * @param slotId The slot that the ImsService is associated with. |
| 4315 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4316 | * the device default. |
| 4317 | * @return the package name of the ImsService configuration. |
| 4318 | */ |
| 4319 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4320 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4321 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4322 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4323 | "getImsService"); |
| 4324 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4325 | final long identity = Binder.clearCallingIdentity(); |
| 4326 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4327 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4328 | if (resolver == null) { |
| 4329 | // may happen if the device does not support IMS. |
| 4330 | return ""; |
| 4331 | } |
| 4332 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4333 | } finally { |
| 4334 | Binder.restoreCallingIdentity(identity); |
| 4335 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4338 | public void setImsRegistrationState(boolean registered) { |
| 4339 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4340 | |
| 4341 | final long identity = Binder.clearCallingIdentity(); |
| 4342 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4343 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4344 | } finally { |
| 4345 | Binder.restoreCallingIdentity(identity); |
| 4346 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4347 | } |
| 4348 | |
| 4349 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4350 | * Set the network selection mode to automatic. |
| 4351 | * |
| 4352 | */ |
| 4353 | @Override |
| 4354 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4356 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4357 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4358 | if (!isActiveSubscription(subId)) { |
| 4359 | return; |
| 4360 | } |
| 4361 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4362 | final long identity = Binder.clearCallingIdentity(); |
| 4363 | try { |
| 4364 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4365 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4366 | } finally { |
| 4367 | Binder.restoreCallingIdentity(identity); |
| 4368 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4369 | } |
| 4370 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4371 | /** |
| 4372 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4373 | * |
| 4374 | * @param subId the id of the subscription. |
| 4375 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4376 | * the operator to attach to. |
| 4377 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4378 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4379 | * normal network selection next time. |
| 4380 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4381 | */ |
| 4382 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4383 | public boolean setNetworkSelectionModeManual( |
| 4384 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4385 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4386 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4387 | |
| 4388 | if (!isActiveSubscription(subId)) { |
| 4389 | return false; |
| 4390 | } |
| 4391 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 | final long identity = Binder.clearCallingIdentity(); |
| 4393 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4394 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4395 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4396 | if (DBG) { |
| 4397 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4398 | + " operator: " + operatorInfo); |
| 4399 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4400 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4401 | } finally { |
| 4402 | Binder.restoreCallingIdentity(identity); |
| 4403 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | /** |
| 4407 | * Scans for available networks. |
| 4408 | */ |
| 4409 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4410 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4411 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4412 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4413 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4414 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4415 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4416 | .setCallingPackage(callingPackage) |
| 4417 | .setCallingPid(Binder.getCallingPid()) |
| 4418 | .setCallingUid(Binder.getCallingUid()) |
| 4419 | .setMethod("getCellNetworkScanResults") |
| 4420 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4421 | .build()); |
| 4422 | switch (locationResult) { |
| 4423 | case DENIED_HARD: |
| 4424 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4425 | case DENIED_SOFT: |
| 4426 | return null; |
| 4427 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4428 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4429 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4430 | try { |
| 4431 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4432 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4433 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4434 | } finally { |
| 4435 | Binder.restoreCallingIdentity(identity); |
| 4436 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4440 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4441 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4442 | * @param subId id of the subscription |
| 4443 | * @param request contains the radio access networks with bands/channels to scan |
| 4444 | * @param messenger callback messenger for scan results or errors |
| 4445 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4446 | * @return the id of the requested scan which can be used to stop the scan. |
| 4447 | */ |
| 4448 | @Override |
| 4449 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4450 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4451 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4452 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4453 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4454 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4455 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4456 | .setCallingPackage(callingPackage) |
| 4457 | .setCallingPid(Binder.getCallingPid()) |
| 4458 | .setCallingUid(Binder.getCallingUid()) |
| 4459 | .setMethod("requestNetworkScan") |
| 4460 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4461 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4462 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4463 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4464 | if (e != null) { |
| 4465 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4466 | throw e; |
| 4467 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4468 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4469 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4470 | } |
| 4471 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4473 | int callingUid = Binder.getCallingUid(); |
| 4474 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4475 | final long identity = Binder.clearCallingIdentity(); |
| 4476 | try { |
| 4477 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4478 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4479 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4480 | } finally { |
| 4481 | Binder.restoreCallingIdentity(identity); |
| 4482 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4483 | } |
| 4484 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4485 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4486 | NetworkScanRequest request, int subId) { |
| 4487 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4488 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4489 | boolean hasNetworkScanPermission = |
| 4490 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4491 | == PERMISSION_GRANTED; |
| 4492 | |
| 4493 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4494 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4495 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4499 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4500 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4501 | return new SecurityException("Specific channels must not be" |
| 4502 | + " scanned without location access."); |
| 4503 | } |
| 4504 | } |
| 4505 | } |
| 4506 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4507 | return null; |
| 4508 | } |
| 4509 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4510 | /** |
| 4511 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4512 | * |
| 4513 | * @param subId id of the subscription |
| 4514 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4515 | */ |
| 4516 | @Override |
| 4517 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4519 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4520 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4521 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4522 | final long identity = Binder.clearCallingIdentity(); |
| 4523 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4524 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | } finally { |
| 4526 | Binder.restoreCallingIdentity(identity); |
| 4527 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4528 | } |
| 4529 | |
| 4530 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4531 | * Get the calculated preferred network type. |
| 4532 | * Used for debugging incorrect network type. |
| 4533 | * |
| 4534 | * @return the preferred network type, defined in RILConstants.java. |
| 4535 | */ |
| 4536 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4537 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4538 | final Phone defaultPhone = getDefaultPhone(); |
| 4539 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4540 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4541 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4542 | } |
| 4543 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4544 | final long identity = Binder.clearCallingIdentity(); |
| 4545 | try { |
| 4546 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4547 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4548 | } finally { |
| 4549 | Binder.restoreCallingIdentity(identity); |
| 4550 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4554 | * Get the preferred network type. |
| 4555 | * Used for device configuration by some CDMA operators. |
| 4556 | * |
| 4557 | * @return the preferred network type, defined in RILConstants.java. |
| 4558 | */ |
| 4559 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4560 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4561 | TelephonyPermissions |
| 4562 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4563 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4564 | |
| 4565 | final long identity = Binder.clearCallingIdentity(); |
| 4566 | try { |
| 4567 | if (DBG) log("getPreferredNetworkType"); |
| 4568 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4569 | int networkType = (result != null ? result[0] : -1); |
| 4570 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4571 | return networkType; |
| 4572 | } finally { |
| 4573 | Binder.restoreCallingIdentity(identity); |
| 4574 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4575 | } |
| 4576 | |
| 4577 | /** |
| 4578 | * Set the preferred network type. |
| 4579 | * Used for device configuration by some CDMA operators. |
| 4580 | * |
| 4581 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4582 | * @return true on success; false on any failure. |
| 4583 | */ |
| 4584 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4585 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4587 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4588 | |
| 4589 | final long identity = Binder.clearCallingIdentity(); |
| 4590 | try { |
| 4591 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4592 | Boolean success = (Boolean) sendRequest( |
| 4593 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4594 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4595 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4596 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4597 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4598 | } |
| 4599 | return success; |
| 4600 | } finally { |
| 4601 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4602 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4603 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4604 | |
| 4605 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4606 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4607 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4608 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4609 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4610 | * @hide |
| 4611 | */ |
| 4612 | @Override |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4613 | public boolean getTetherApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4614 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4615 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4616 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4617 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 4618 | if (phone != null) { |
| 4619 | return phone.hasMatchedTetherApnSetting(); |
| 4620 | } else { |
| 4621 | return false; |
| 4622 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4623 | } finally { |
| 4624 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4625 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4629 | * Set mobile data enabled |
| 4630 | * Used by the user through settings etc to turn on/off mobile data |
| 4631 | * |
| 4632 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4633 | */ |
| 4634 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4635 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4637 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4638 | |
| 4639 | final long identity = Binder.clearCallingIdentity(); |
| 4640 | try { |
| 4641 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4642 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4643 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4644 | if (phone != null) { |
| 4645 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4646 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4647 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4648 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4649 | } |
| 4650 | } finally { |
| 4651 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4652 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4656 | * Get the user enabled state of Mobile Data. |
| 4657 | * |
| 4658 | * TODO: remove and use isUserDataEnabled. |
| 4659 | * This can't be removed now because some vendor codes |
| 4660 | * calls through ITelephony directly while they should |
| 4661 | * use TelephonyManager. |
| 4662 | * |
| 4663 | * @return true on enabled |
| 4664 | */ |
| 4665 | @Override |
| 4666 | public boolean getDataEnabled(int subId) { |
| 4667 | return isUserDataEnabled(subId); |
| 4668 | } |
| 4669 | |
| 4670 | /** |
| 4671 | * Get whether mobile data is enabled per user setting. |
| 4672 | * |
| 4673 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4674 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4675 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4676 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4677 | * |
| 4678 | * @return {@code true} if data is enabled else {@code false} |
| 4679 | */ |
| 4680 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4681 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4682 | try { |
| 4683 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4684 | null); |
| 4685 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4686 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4687 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4688 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4689 | |
| 4690 | final long identity = Binder.clearCallingIdentity(); |
| 4691 | try { |
| 4692 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4693 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4694 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4695 | if (phone != null) { |
| 4696 | boolean retVal = phone.isUserDataEnabled(); |
| 4697 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4698 | return retVal; |
| 4699 | } else { |
| 4700 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4701 | return false; |
| 4702 | } |
| 4703 | } finally { |
| 4704 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4705 | } |
| 4706 | } |
| 4707 | |
| 4708 | /** |
| 4709 | * Get whether mobile data is enabled. |
| 4710 | * |
| 4711 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4712 | * whether mobile data is actually enabled. |
| 4713 | * |
| 4714 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4715 | * |
| 4716 | * @return {@code true} if data is enabled else {@code false} |
| 4717 | */ |
| 4718 | @Override |
| 4719 | public boolean isDataEnabled(int subId) { |
| 4720 | try { |
| 4721 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4722 | null); |
| 4723 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4725 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4726 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4727 | |
| 4728 | final long identity = Binder.clearCallingIdentity(); |
| 4729 | try { |
| 4730 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4731 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4732 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4733 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4734 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4736 | return retVal; |
| 4737 | } else { |
| 4738 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4739 | return false; |
| 4740 | } |
| 4741 | } finally { |
| 4742 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4743 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4744 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4745 | |
| 4746 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4747 | public int getCarrierPrivilegeStatus(int subId) { |
| 4748 | final Phone phone = getPhone(subId); |
| 4749 | if (phone == null) { |
| 4750 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4751 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4752 | } |
| 4753 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4754 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4755 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4756 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4757 | } |
| 4758 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4759 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4760 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4761 | |
| 4762 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4763 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4764 | final Phone phone = getPhone(subId); |
| 4765 | if (phone == null) { |
| 4766 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4767 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4768 | } |
| 4769 | UiccProfile profile = |
| 4770 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4771 | if (profile == null) { |
| 4772 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4773 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4774 | } |
| 4775 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4776 | } |
| 4777 | |
| 4778 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4779 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 4780 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4781 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 4785 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4786 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4787 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4788 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4789 | } |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4790 | |
| 4791 | return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | @Override |
| 4795 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4796 | if (TextUtils.isEmpty(pkgName)) |
| 4797 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4798 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4799 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4800 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4801 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4802 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4803 | continue; |
| 4804 | } |
| 4805 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4806 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4807 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4808 | break; |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4813 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4814 | |
| 4815 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4816 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4817 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4818 | loge("phoneId " + phoneId + " is not valid."); |
| 4819 | return null; |
| 4820 | } |
| 4821 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4822 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4823 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4824 | return null ; |
| 4825 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4826 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4827 | } |
| 4828 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4829 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4830 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4831 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4832 | List<String> privilegedPackages = new ArrayList<>(); |
| 4833 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4834 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 4835 | // has UICC in that slot. |
| 4836 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4837 | if (card.hasCarrierPrivilegeRules()) { |
| 4838 | if (packages == null) { |
| 4839 | // Only check packages in user 0 for now |
| 4840 | packages = pm.getInstalledPackagesAsUser( |
| 4841 | PackageManager.MATCH_DISABLED_COMPONENTS |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4842 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4843 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4844 | } |
| 4845 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4846 | PackageInfo pkgInfo = packages.get(p); |
| 4847 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4848 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4849 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4850 | privilegedPackages.add(pkgInfo.packageName); |
| 4851 | } |
| 4852 | } |
| 4853 | } |
| 4854 | } |
| 4855 | return privilegedPackages; |
| 4856 | } |
| 4857 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 4858 | @Override |
| 4859 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
| 4860 | List<String> privilegedPackages = new ArrayList<>(); |
| 4861 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4862 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 4863 | } |
| 4864 | return privilegedPackages; |
| 4865 | } |
| 4866 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4867 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4868 | final Phone phone = getPhone(subId); |
| 4869 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4870 | if (card == null) { |
| 4871 | loge("getIccId: No UICC"); |
| 4872 | return null; |
| 4873 | } |
| 4874 | String iccId = card.getIccId(); |
| 4875 | if (TextUtils.isEmpty(iccId)) { |
| 4876 | loge("getIccId: ICC ID is null or empty."); |
| 4877 | return null; |
| 4878 | } |
| 4879 | return iccId; |
| 4880 | } |
| 4881 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4882 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4883 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4884 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4885 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4886 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | try { |
| 4890 | final String iccId = getIccId(subId); |
| 4891 | final Phone phone = getPhone(subId); |
| 4892 | if (phone == null) { |
| 4893 | return false; |
| 4894 | } |
| 4895 | final String subscriberId = phone.getSubscriberId(); |
| 4896 | |
| 4897 | if (DBG_MERGE) { |
| 4898 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4899 | + subscriberId + " to " + number); |
| 4900 | } |
| 4901 | |
| 4902 | if (TextUtils.isEmpty(iccId)) { |
| 4903 | return false; |
| 4904 | } |
| 4905 | |
| 4906 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4907 | |
| 4908 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4909 | if (alphaTag == null) { |
| 4910 | editor.remove(alphaTagPrefKey); |
| 4911 | } else { |
| 4912 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4913 | } |
| 4914 | |
| 4915 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4916 | // track all merged IMSIs based on line number |
| 4917 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4918 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4919 | if (number == null) { |
| 4920 | editor.remove(numberPrefKey); |
| 4921 | editor.remove(subscriberPrefKey); |
| 4922 | } else { |
| 4923 | editor.putString(numberPrefKey, number); |
| 4924 | editor.putString(subscriberPrefKey, subscriberId); |
| 4925 | } |
| 4926 | |
| 4927 | editor.commit(); |
| 4928 | return true; |
| 4929 | } finally { |
| 4930 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4931 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4935 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4936 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4937 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4938 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4939 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4940 | return null; |
| 4941 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4942 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | final long identity = Binder.clearCallingIdentity(); |
| 4944 | try { |
| 4945 | String iccId = getIccId(subId); |
| 4946 | if (iccId != null) { |
| 4947 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4948 | if (DBG_MERGE) { |
| 4949 | log("getLine1NumberForDisplay returning " |
| 4950 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4951 | } |
| 4952 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4953 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4955 | return null; |
| 4956 | } finally { |
| 4957 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4958 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4962 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4963 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4964 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4965 | return null; |
| 4966 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4968 | final long identity = Binder.clearCallingIdentity(); |
| 4969 | try { |
| 4970 | String iccId = getIccId(subId); |
| 4971 | if (iccId != null) { |
| 4972 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4973 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4974 | } |
| 4975 | return null; |
| 4976 | } finally { |
| 4977 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4978 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4979 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4980 | |
| 4981 | @Override |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 4982 | public String[] getMergedSubscriberIds(int subId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4983 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4984 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4986 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4987 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4988 | return null; |
| 4989 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4990 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 4991 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4992 | // the process, where TelephonyManager was instantiated. |
| 4993 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4994 | final long identity = Binder.clearCallingIdentity(); |
| 4995 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4996 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4997 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4998 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4999 | |
| 5000 | // Figure out what subscribers are currently active |
| 5001 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5002 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5003 | // Only consider subs which match the current subId |
| 5004 | // This logic can be simplified. See b/131189269 for progress. |
| 5005 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5006 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5007 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5008 | |
| 5009 | // First pass, find a number override for an active subscriber |
| 5010 | String mergeNumber = null; |
| 5011 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5012 | for (String key : prefs.keySet()) { |
| 5013 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5014 | final String subscriberId = (String) prefs.get(key); |
| 5015 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5016 | final String iccId = key.substring( |
| 5017 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5018 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5019 | mergeNumber = (String) prefs.get(numberKey); |
| 5020 | if (DBG_MERGE) { |
| 5021 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5022 | + " for active subscriber " + subscriberId); |
| 5023 | } |
| 5024 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5025 | break; |
| 5026 | } |
| 5027 | } |
| 5028 | } |
| 5029 | } |
| 5030 | |
| 5031 | // Shortcut when no active merged subscribers |
| 5032 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5033 | return null; |
| 5034 | } |
| 5035 | |
| 5036 | // Second pass, find all subscribers under that line override |
| 5037 | final ArraySet<String> result = new ArraySet<>(); |
| 5038 | for (String key : prefs.keySet()) { |
| 5039 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5040 | final String number = (String) prefs.get(key); |
| 5041 | if (mergeNumber.equals(number)) { |
| 5042 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5043 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5044 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5045 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5046 | result.add(subscriberId); |
| 5047 | } |
| 5048 | } |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5053 | Arrays.sort(resultArray); |
| 5054 | if (DBG_MERGE) { |
| 5055 | Slog.d(LOG_TAG, |
| 5056 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5057 | } |
| 5058 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5061 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5065 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5066 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5067 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5068 | |
| 5069 | final long identity = Binder.clearCallingIdentity(); |
| 5070 | try { |
| 5071 | final Phone phone = getPhone(subId); |
| 5072 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5073 | } finally { |
| 5074 | Binder.restoreCallingIdentity(identity); |
| 5075 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5076 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5077 | |
| 5078 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5079 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5080 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5081 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5082 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | |
| 5084 | final long identity = Binder.clearCallingIdentity(); |
| 5085 | try { |
| 5086 | final Phone phone = getPhone(subId); |
| 5087 | if (phone == null) { |
| 5088 | return false; |
| 5089 | } |
| 5090 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5091 | cdmaNonRoamingList); |
| 5092 | } finally { |
| 5093 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5094 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5098 | @Deprecated |
| 5099 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5100 | enforceModifyPermission(); |
| 5101 | |
| 5102 | int returnValue = 0; |
| 5103 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5104 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5105 | if(result.exception == null) { |
| 5106 | if (result.result != null) { |
| 5107 | byte[] responseData = (byte[])(result.result); |
| 5108 | if(responseData.length > oemResp.length) { |
| 5109 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5110 | responseData.length + "bytes. Buffer Size is " + |
| 5111 | oemResp.length + "bytes."); |
| 5112 | } |
| 5113 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5114 | returnValue = responseData.length; |
| 5115 | } |
| 5116 | } else { |
| 5117 | CommandException ex = (CommandException) result.exception; |
| 5118 | returnValue = ex.getCommandError().ordinal(); |
| 5119 | if(returnValue > 0) returnValue *= -1; |
| 5120 | } |
| 5121 | } catch (RuntimeException e) { |
| 5122 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5123 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5124 | if(returnValue > 0) returnValue *= -1; |
| 5125 | } |
| 5126 | |
| 5127 | return returnValue; |
| 5128 | } |
| 5129 | |
| 5130 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5131 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5132 | try { |
| 5133 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5134 | } catch (RuntimeException e) { |
| 5135 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5136 | } |
| 5137 | } |
| 5138 | |
| 5139 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5140 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5141 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5142 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5143 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5144 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5145 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5146 | final long identity = Binder.clearCallingIdentity(); |
| 5147 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5148 | TelephonyPermissions |
| 5149 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5150 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5151 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5152 | } finally { |
| 5153 | Binder.restoreCallingIdentity(identity); |
| 5154 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5155 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5156 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5157 | |
| 5158 | @Override |
| 5159 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5160 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5161 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | |
| 5163 | final long identity = Binder.clearCallingIdentity(); |
| 5164 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5165 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5166 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5167 | } finally { |
| 5168 | Binder.restoreCallingIdentity(identity); |
| 5169 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5173 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5174 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5175 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5176 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5177 | return false; |
| 5178 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5179 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5180 | final long identity = Binder.clearCallingIdentity(); |
| 5181 | try { |
| 5182 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5183 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5184 | // In the long run, we may instead need to check if there exists a connection service |
| 5185 | // which can support video calling. |
| 5186 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5187 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5188 | return imsManager.isVtEnabledByPlatform() |
| 5189 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5190 | && imsManager.isVtEnabledByUser(); |
| 5191 | } finally { |
| 5192 | Binder.restoreCallingIdentity(identity); |
| 5193 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5194 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5195 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5196 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5197 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5198 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5199 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5200 | return false; |
| 5201 | } |
| 5202 | |
| 5203 | final long identity = Binder.clearCallingIdentity(); |
| 5204 | try { |
| 5205 | CarrierConfigManager configManager = |
| 5206 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5207 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5209 | } finally { |
| 5210 | Binder.restoreCallingIdentity(identity); |
| 5211 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5215 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5216 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5217 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5218 | return false; |
| 5219 | } |
| 5220 | |
| 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
| 5223 | CarrierConfigManager configManager = |
| 5224 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5225 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5226 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5227 | } finally { |
| 5228 | Binder.restoreCallingIdentity(identity); |
| 5229 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5230 | } |
| 5231 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5232 | @Override |
| 5233 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5234 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5235 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | @Override |
| 5239 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5240 | final long identity = Binder.clearCallingIdentity(); |
| 5241 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5242 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5243 | } finally { |
| 5244 | Binder.restoreCallingIdentity(identity); |
| 5245 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5248 | /** |
| 5249 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5250 | * support for the feature and device firmware support. |
| 5251 | * |
| 5252 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5253 | */ |
| 5254 | @Override |
| 5255 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5256 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5257 | final Phone phone = getPhone(subscriptionId); |
| 5258 | if (phone == null) { |
| 5259 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5260 | return false; |
| 5261 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5263 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5264 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5265 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5266 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5267 | return isCarrierSupported && isDeviceSupported; |
| 5268 | } finally { |
| 5269 | Binder.restoreCallingIdentity(identity); |
| 5270 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5271 | } |
| 5272 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5273 | /** |
| 5274 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5275 | * both also support RTT. |
| 5276 | */ |
| 5277 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5278 | final long identity = Binder.clearCallingIdentity(); |
| 5279 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5280 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5281 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5282 | } finally { |
| 5283 | Binder.restoreCallingIdentity(identity); |
| 5284 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5285 | } |
| 5286 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5287 | /** |
| 5288 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5289 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5290 | * |
| 5291 | * <p>Requires Permission: |
| 5292 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5293 | */ |
| 5294 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5295 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5296 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5297 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5298 | return null; |
| 5299 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5300 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5301 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5302 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5303 | return null; |
| 5304 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5305 | |
| 5306 | final long identity = Binder.clearCallingIdentity(); |
| 5307 | try { |
| 5308 | return phone.getDeviceId(); |
| 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
| 5311 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5312 | } |
| 5313 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5314 | /** |
| 5315 | * {@hide} |
| 5316 | * Returns the IMS Registration Status on a particular subid |
| 5317 | * |
| 5318 | * @param subId |
| 5319 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5320 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5321 | Phone phone = getPhone(subId); |
| 5322 | if (phone != null) { |
| 5323 | return phone.isImsRegistered(); |
| 5324 | } else { |
| 5325 | return false; |
| 5326 | } |
| 5327 | } |
| 5328 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5329 | @Override |
| 5330 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5331 | final long identity = Binder.clearCallingIdentity(); |
| 5332 | try { |
| 5333 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5334 | } finally { |
| 5335 | Binder.restoreCallingIdentity(identity); |
| 5336 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5337 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5338 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5339 | @Override |
| 5340 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5341 | final long identity = Binder.clearCallingIdentity(); |
| 5342 | try { |
| 5343 | Phone phone = getPhone(subscriptionId); |
| 5344 | if (phone == null) { |
| 5345 | return null; |
| 5346 | } |
| 5347 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5348 | } finally { |
| 5349 | Binder.restoreCallingIdentity(identity); |
| 5350 | } |
| 5351 | } |
| 5352 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5353 | /** |
| 5354 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5355 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5356 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | final long identity = Binder.clearCallingIdentity(); |
| 5358 | try { |
| 5359 | Phone phone = getPhone(subId); |
| 5360 | if (phone != null) { |
| 5361 | return phone.isWifiCallingEnabled(); |
| 5362 | } else { |
| 5363 | return false; |
| 5364 | } |
| 5365 | } finally { |
| 5366 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5367 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5368 | } |
| 5369 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5370 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5371 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5372 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5373 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5374 | final long identity = Binder.clearCallingIdentity(); |
| 5375 | try { |
| 5376 | Phone phone = getPhone(subId); |
| 5377 | if (phone != null) { |
| 5378 | return phone.isVideoEnabled(); |
| 5379 | } else { |
| 5380 | return false; |
| 5381 | } |
| 5382 | } finally { |
| 5383 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5384 | } |
| 5385 | } |
| 5386 | |
| 5387 | /** |
| 5388 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5389 | * defined in {@link ImsRegistrationImplBase}. |
| 5390 | */ |
| 5391 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | final long identity = Binder.clearCallingIdentity(); |
| 5393 | try { |
| 5394 | Phone phone = getPhone(subId); |
| 5395 | if (phone != null) { |
| 5396 | return phone.getImsRegistrationTech(); |
| 5397 | } else { |
| 5398 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5399 | } |
| 5400 | } finally { |
| 5401 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5402 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5403 | } |
| 5404 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5405 | @Override |
| 5406 | public void factoryReset(int subId) { |
| 5407 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5408 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5409 | return; |
| 5410 | } |
| 5411 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5412 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5413 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5414 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5415 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5416 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5417 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5418 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5419 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5420 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5421 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5422 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5423 | // There has been issues when Sms raw table somehow stores orphan |
| 5424 | // fragments. They lead to garbled message when new fragments come |
| 5425 | // in and combined with those stale ones. In case this happens again, |
| 5426 | // user can reset all network settings which will clean up this table. |
| 5427 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5428 | } finally { |
| 5429 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5430 | } |
| 5431 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5432 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5433 | private void cleanUpSmsRawTable(Context context) { |
| 5434 | ContentResolver resolver = context.getContentResolver(); |
| 5435 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5436 | resolver.delete(uri, null, null); |
| 5437 | } |
| 5438 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5439 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5440 | public String getSimLocaleForSubscriber(int subId) { |
| 5441 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5442 | final Phone phone = getPhone(subId); |
| 5443 | if (phone == null) { |
| 5444 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5445 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5446 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | final long identity = Binder.clearCallingIdentity(); |
| 5448 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5449 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5450 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5451 | if (info == null) { |
| 5452 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5453 | return null; |
| 5454 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5455 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5456 | // preferences (EF-PL and EF-LI)... |
| 5457 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5458 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5459 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5460 | if (localeFromDefaultSim != null) { |
| 5461 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5462 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5463 | + localeFromDefaultSim); |
| 5464 | return localeFromDefaultSim.toLanguageTag(); |
| 5465 | } else { |
| 5466 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5467 | } |
| 5468 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5469 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5470 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5471 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5472 | // the SIM and carrier preferences does not include a country we add the country |
| 5473 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5474 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5476 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | return mccLocale.toLanguageTag(); |
| 5478 | } |
| 5479 | |
| 5480 | if (DBG) log("No locale found - returning null"); |
| 5481 | return null; |
| 5482 | } finally { |
| 5483 | Binder.restoreCallingIdentity(identity); |
| 5484 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5488 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5489 | } |
| 5490 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 | /** |
| 5492 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5493 | */ |
| 5494 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5495 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5496 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5497 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5498 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5499 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5500 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5501 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5502 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5503 | * representing the state of the modem. |
| 5504 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5505 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5506 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5507 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5508 | */ |
| 5509 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5510 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5511 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5512 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5513 | |
| 5514 | final long identity = Binder.clearCallingIdentity(); |
| 5515 | try { |
| 5516 | ModemActivityInfo ret = null; |
| 5517 | synchronized (mLastModemActivityInfo) { |
| 5518 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5519 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5520 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5521 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5523 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5524 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5525 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5526 | } |
| 5527 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5528 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5529 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5530 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5531 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5532 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5533 | mLastModemActivityInfo.setRxTimeMillis( |
| 5534 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5535 | mLastModemActivityInfo.setEnergyUsed( |
| 5536 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5537 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5538 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5539 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5540 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5541 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5542 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5543 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5544 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5545 | Bundle bundle = new Bundle(); |
| 5546 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5547 | result.send(0, bundle); |
| 5548 | } finally { |
| 5549 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5550 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5551 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5552 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5553 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5554 | // less than total activity duration. |
| 5555 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5556 | if (info == null) { |
| 5557 | return false; |
| 5558 | } |
| 5559 | int activityDurationMs = |
| 5560 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5561 | int totalTxTimeMs = 0; |
| 5562 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5563 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5564 | } |
| 5565 | return (info.isValid() |
| 5566 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5567 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5568 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5569 | && (totalTxTimeMs <= activityDurationMs)); |
| 5570 | } |
| 5571 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5572 | /** |
| 5573 | * {@hide} |
| 5574 | * Returns the service state information on specified subscription. |
| 5575 | */ |
| 5576 | @Override |
| 5577 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5578 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5579 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5580 | return null; |
| 5581 | } |
| 5582 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5583 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5584 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5585 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5586 | .setCallingPackage(callingPackage) |
| 5587 | .setCallingPid(Binder.getCallingPid()) |
| 5588 | .setCallingUid(Binder.getCallingUid()) |
| 5589 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5590 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5591 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5592 | .build()); |
| 5593 | |
| 5594 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5595 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5596 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5597 | .setCallingPackage(callingPackage) |
| 5598 | .setCallingPid(Binder.getCallingPid()) |
| 5599 | .setCallingUid(Binder.getCallingUid()) |
| 5600 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 5601 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5602 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5603 | .build()); |
| 5604 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5605 | boolean hasFinePermission = |
| 5606 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5607 | boolean hasCoarsePermission = |
| 5608 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5609 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5610 | final long identity = Binder.clearCallingIdentity(); |
| 5611 | try { |
| 5612 | final Phone phone = getPhone(subId); |
| 5613 | if (phone == null) { |
| 5614 | return null; |
| 5615 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5616 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5617 | ServiceState ss = phone.getServiceState(); |
| 5618 | |
| 5619 | // Scrub out the location info in ServiceState depending on what level of access |
| 5620 | // the caller has. |
| 5621 | if (hasFinePermission) return ss; |
| 5622 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5623 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | } finally { |
| 5625 | Binder.restoreCallingIdentity(identity); |
| 5626 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5627 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5628 | |
| 5629 | /** |
| 5630 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5631 | * |
| 5632 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5633 | * voicemail ringtone. |
| 5634 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5635 | * PhoneAccount. |
| 5636 | */ |
| 5637 | @Override |
| 5638 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | final long identity = Binder.clearCallingIdentity(); |
| 5640 | try { |
| 5641 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5642 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5643 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5645 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5646 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5647 | } finally { |
| 5648 | Binder.restoreCallingIdentity(identity); |
| 5649 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5650 | } |
| 5651 | |
| 5652 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5653 | * Sets the per-account voicemail ringtone. |
| 5654 | * |
| 5655 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5656 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5657 | * |
| 5658 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5659 | * voicemail ringtone. |
| 5660 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5661 | * PhoneAccount. |
| 5662 | */ |
| 5663 | @Override |
| 5664 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5665 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5666 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5667 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5668 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5669 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5671 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5672 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5673 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | |
| 5675 | final long identity = Binder.clearCallingIdentity(); |
| 5676 | try { |
| 5677 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5678 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5679 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5680 | } |
| 5681 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5682 | } finally { |
| 5683 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5684 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5688 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5689 | * |
| 5690 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5691 | * voicemail vibration setting. |
| 5692 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5693 | */ |
| 5694 | @Override |
| 5695 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | final long identity = Binder.clearCallingIdentity(); |
| 5697 | try { |
| 5698 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5699 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5700 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5701 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5702 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5703 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5704 | } finally { |
| 5705 | Binder.restoreCallingIdentity(identity); |
| 5706 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5707 | } |
| 5708 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5709 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5710 | * Sets the per-account voicemail vibration. |
| 5711 | * |
| 5712 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5713 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5714 | * |
| 5715 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5716 | * voicemail vibration setting. |
| 5717 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5718 | * specific PhoneAccount. |
| 5719 | */ |
| 5720 | @Override |
| 5721 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5722 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5723 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5724 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5725 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5726 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5728 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5729 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5730 | } |
| 5731 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | final long identity = Binder.clearCallingIdentity(); |
| 5733 | try { |
| 5734 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5735 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5736 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5737 | } |
| 5738 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5739 | } finally { |
| 5740 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5741 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5745 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5746 | * |
| 5747 | * @throws SecurityException if the caller does not have the required permission |
| 5748 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5749 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5750 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5751 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5755 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5756 | * permission. |
| 5757 | * |
| 5758 | * @throws SecurityException if the caller does not have the required permission |
| 5759 | */ |
| 5760 | private void enforceSendSmsPermission() { |
| 5761 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5762 | } |
| 5763 | |
| 5764 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5765 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5766 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5767 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5768 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5769 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | final long identity = Binder.clearCallingIdentity(); |
| 5771 | try { |
| 5772 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5773 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | if (componentName == null) { |
| 5775 | throw new SecurityException( |
| 5776 | "Caller not current active visual voicemail package[null]"); |
| 5777 | } |
| 5778 | String vvmPackage = componentName.getPackageName(); |
| 5779 | if (!callingPackage.equals(vvmPackage)) { |
| 5780 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5781 | + vvmPackage + "]"); |
| 5782 | } |
| 5783 | } finally { |
| 5784 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5789 | * Return the application ID for the app type. |
| 5790 | * |
| 5791 | * @param subId the subscription ID that this request applies to. |
| 5792 | * @param appType the uicc app type. |
| 5793 | * @return Application ID for specificied app type, or null if no uicc. |
| 5794 | */ |
| 5795 | @Override |
| 5796 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5797 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5798 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | |
| 5800 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5801 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5802 | if (phone == null) { |
| 5803 | return null; |
| 5804 | } |
| 5805 | String aid = null; |
| 5806 | try { |
| 5807 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5808 | .getApplicationByType(appType).getAid(); |
| 5809 | } catch (Exception e) { |
| 5810 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5811 | } |
| 5812 | return aid; |
| 5813 | } finally { |
| 5814 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5815 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5816 | } |
| 5817 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5818 | /** |
| 5819 | * Return the Electronic Serial Number. |
| 5820 | * |
| 5821 | * @param subId the subscription ID that this request applies to. |
| 5822 | * @return ESN or null if error. |
| 5823 | */ |
| 5824 | @Override |
| 5825 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5826 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5827 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5828 | |
| 5829 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5830 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 | if (phone == null) { |
| 5832 | return null; |
| 5833 | } |
| 5834 | String esn = null; |
| 5835 | try { |
| 5836 | esn = phone.getEsn(); |
| 5837 | } catch (Exception e) { |
| 5838 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5839 | } |
| 5840 | return esn; |
| 5841 | } finally { |
| 5842 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5843 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5844 | } |
| 5845 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5846 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5847 | * Return the Preferred Roaming List Version. |
| 5848 | * |
| 5849 | * @param subId the subscription ID that this request applies to. |
| 5850 | * @return PRLVersion or null if error. |
| 5851 | */ |
| 5852 | @Override |
| 5853 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5854 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5855 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | |
| 5857 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5858 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5859 | if (phone == null) { |
| 5860 | return null; |
| 5861 | } |
| 5862 | String cdmaPrlVersion = null; |
| 5863 | try { |
| 5864 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5865 | } catch (Exception e) { |
| 5866 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5867 | } |
| 5868 | return cdmaPrlVersion; |
| 5869 | } finally { |
| 5870 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5871 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5875 | * Get snapshot of Telephony histograms |
| 5876 | * @return List of Telephony histograms |
| 5877 | * @hide |
| 5878 | */ |
| 5879 | @Override |
| 5880 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5881 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5882 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5883 | |
| 5884 | final long identity = Binder.clearCallingIdentity(); |
| 5885 | try { |
| 5886 | return RIL.getTelephonyRILTimingHistograms(); |
| 5887 | } finally { |
| 5888 | Binder.restoreCallingIdentity(identity); |
| 5889 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5890 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5891 | |
| 5892 | /** |
| 5893 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5894 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5895 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5896 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5897 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5898 | * @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] | 5899 | */ |
| 5900 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5901 | @TelephonyManager.SetCarrierRestrictionResult |
| 5902 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5903 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5904 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5905 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5906 | if (carrierRestrictionRules == null) { |
| 5907 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5908 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5909 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5910 | final long identity = Binder.clearCallingIdentity(); |
| 5911 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5912 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5913 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | } finally { |
| 5915 | Binder.restoreCallingIdentity(identity); |
| 5916 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5917 | } |
| 5918 | |
| 5919 | /** |
| 5920 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5921 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5922 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5923 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5924 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5925 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5926 | */ |
| 5927 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5928 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5929 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5930 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5931 | |
| 5932 | final long identity = Binder.clearCallingIdentity(); |
| 5933 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5934 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5935 | if (response instanceof CarrierRestrictionRules) { |
| 5936 | return (CarrierRestrictionRules) response; |
| 5937 | } |
| 5938 | // Response is an Exception of some kind, |
| 5939 | // which is signalled to the user as a NULL retval |
| 5940 | return null; |
| 5941 | } catch (Exception e) { |
| 5942 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5943 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5944 | } finally { |
| 5945 | Binder.restoreCallingIdentity(identity); |
| 5946 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5949 | /** |
| 5950 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5951 | * @param subId the subscription ID that this action applies to. |
| 5952 | * @param enabled control enable or disable metered apns. |
| 5953 | * {@hide} |
| 5954 | */ |
| 5955 | @Override |
| 5956 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5957 | enforceModifyPermission(); |
| 5958 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5959 | |
| 5960 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5961 | if (phone == null) { |
| 5962 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5963 | return; |
| 5964 | } |
| 5965 | try { |
| 5966 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5967 | } catch (Exception e) { |
| 5968 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | } finally { |
| 5970 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5971 | } |
| 5972 | } |
| 5973 | |
| 5974 | /** |
| 5975 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5976 | * @param subId the subscription ID that this action applies to. |
| 5977 | * @param enabled control enable or disable radio. |
| 5978 | * {@hide} |
| 5979 | */ |
| 5980 | @Override |
| 5981 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5982 | enforceModifyPermission(); |
| 5983 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5984 | |
| 5985 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5986 | if (phone == null) { |
| 5987 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5988 | return; |
| 5989 | } |
| 5990 | try { |
| 5991 | phone.carrierActionSetRadioEnabled(enabled); |
| 5992 | } catch (Exception e) { |
| 5993 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | } finally { |
| 5995 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5996 | } |
| 5997 | } |
| 5998 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5999 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6000 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6001 | * network status based on which carrier apps could apply actions accordingly, |
| 6002 | * enable/disable default url handler for example. |
| 6003 | * |
| 6004 | * @param subId the subscription ID that this action applies to. |
| 6005 | * @param report control start/stop reporting the default network status. |
| 6006 | * {@hide} |
| 6007 | */ |
| 6008 | @Override |
| 6009 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6010 | enforceModifyPermission(); |
| 6011 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | |
| 6013 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6014 | if (phone == null) { |
| 6015 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6016 | return; |
| 6017 | } |
| 6018 | try { |
| 6019 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6020 | } catch (Exception e) { |
| 6021 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6028 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6029 | * @param subId the subscription ID that this action applies to. |
| 6030 | * {@hide} |
| 6031 | */ |
| 6032 | @Override |
| 6033 | public void carrierActionResetAll(int subId) { |
| 6034 | enforceModifyPermission(); |
| 6035 | final Phone phone = getPhone(subId); |
| 6036 | if (phone == null) { |
| 6037 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6038 | return; |
| 6039 | } |
| 6040 | try { |
| 6041 | phone.carrierActionResetAll(); |
| 6042 | } catch (Exception e) { |
| 6043 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6044 | } |
| 6045 | } |
| 6046 | |
| 6047 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6048 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6049 | * bug report is being generated. |
| 6050 | */ |
| 6051 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6052 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6053 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6054 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6055 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6056 | + Binder.getCallingPid() |
| 6057 | + ", uid=" + Binder.getCallingUid() |
| 6058 | + "without permission " |
| 6059 | + android.Manifest.permission.DUMP); |
| 6060 | return; |
| 6061 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6062 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6063 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6064 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6065 | @Override |
| 6066 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 6067 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 6068 | throws RemoteException { |
| 6069 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 6070 | } |
| 6071 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6072 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6073 | * Get aggregated video call data usage since boot. |
| 6074 | * |
| 6075 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6076 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6077 | * {@hide} |
| 6078 | */ |
| 6079 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6080 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6081 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6082 | null); |
| 6083 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6084 | final long identity = Binder.clearCallingIdentity(); |
| 6085 | try { |
| 6086 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6087 | // records the delta with the corresponding network identity. |
| 6088 | // We just return the total video call data usage snapshot since boot. |
| 6089 | Phone phone = getPhone(subId); |
| 6090 | if (phone != null) { |
| 6091 | return phone.getVtDataUsage(perUidStats); |
| 6092 | } |
| 6093 | return null; |
| 6094 | } finally { |
| 6095 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6096 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6097 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6098 | |
| 6099 | /** |
| 6100 | * Policy control of data connection. Usually used when data limit is passed. |
| 6101 | * @param enabled True if enabling the data, otherwise disabling. |
| 6102 | * @param subId Subscription index |
| 6103 | * {@hide} |
| 6104 | */ |
| 6105 | @Override |
| 6106 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6107 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6108 | |
| 6109 | final long identity = Binder.clearCallingIdentity(); |
| 6110 | try { |
| 6111 | Phone phone = getPhone(subId); |
| 6112 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6113 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6114 | } |
| 6115 | } finally { |
| 6116 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6117 | } |
| 6118 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6119 | |
| 6120 | /** |
| 6121 | * Get Client request stats |
| 6122 | * @return List of Client Request Stats |
| 6123 | * @hide |
| 6124 | */ |
| 6125 | @Override |
| 6126 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6127 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6128 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6129 | return null; |
| 6130 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6131 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6132 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | final long identity = Binder.clearCallingIdentity(); |
| 6134 | try { |
| 6135 | if (phone != null) { |
| 6136 | return phone.getClientRequestStats(); |
| 6137 | } |
| 6138 | |
| 6139 | return null; |
| 6140 | } finally { |
| 6141 | Binder.restoreCallingIdentity(identity); |
| 6142 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6143 | } |
| 6144 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6145 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6146 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6147 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6148 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6149 | |
| 6150 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6151 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6152 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6153 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6154 | * @param state State of SIM (power down, power up, pass through) |
| 6155 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6156 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6157 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6158 | * |
| 6159 | **/ |
| 6160 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6161 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6162 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6163 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6164 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6165 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6166 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6167 | final long identity = Binder.clearCallingIdentity(); |
| 6168 | try { |
| 6169 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6170 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | } |
| 6172 | } finally { |
| 6173 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6174 | } |
| 6175 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6176 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6177 | private boolean isUssdApiAllowed(int subId) { |
| 6178 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6179 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6180 | if (configManager == null) { |
| 6181 | return false; |
| 6182 | } |
| 6183 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6184 | if (pb == null) { |
| 6185 | return false; |
| 6186 | } |
| 6187 | return pb.getBoolean( |
| 6188 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6189 | } |
| 6190 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6191 | /** |
| 6192 | * Check if phone is in emergency callback mode |
| 6193 | * @return true if phone is in emergency callback mode |
| 6194 | * @param subId sub id |
| 6195 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6196 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6197 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6198 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6199 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6200 | |
| 6201 | final long identity = Binder.clearCallingIdentity(); |
| 6202 | try { |
| 6203 | if (phone != null) { |
| 6204 | return phone.isInEcm(); |
| 6205 | } else { |
| 6206 | return false; |
| 6207 | } |
| 6208 | } finally { |
| 6209 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6210 | } |
| 6211 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6212 | |
| 6213 | /** |
| 6214 | * Get the current signal strength information for the given subscription. |
| 6215 | * Because this information is not updated when the device is in a low power state |
| 6216 | * it should not be relied-upon to be current. |
| 6217 | * @param subId Subscription index |
| 6218 | * @return the most recent cached signal strength info from the modem |
| 6219 | */ |
| 6220 | @Override |
| 6221 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6222 | final long identity = Binder.clearCallingIdentity(); |
| 6223 | try { |
| 6224 | Phone p = getPhone(subId); |
| 6225 | if (p == null) { |
| 6226 | return null; |
| 6227 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6228 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6229 | return p.getSignalStrength(); |
| 6230 | } finally { |
| 6231 | Binder.restoreCallingIdentity(identity); |
| 6232 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6233 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6234 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6235 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6236 | * Get the current modem radio state for the given slot. |
| 6237 | * @param slotIndex slot index. |
| 6238 | * @param callingPackage the name of the package making the call. |
| 6239 | * @return the current radio power state from the modem |
| 6240 | */ |
| 6241 | @Override |
| 6242 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6243 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6244 | if (phone != null) { |
| 6245 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6246 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6247 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6248 | } |
| 6249 | |
| 6250 | final long identity = Binder.clearCallingIdentity(); |
| 6251 | try { |
| 6252 | return phone.getRadioPowerState(); |
| 6253 | } finally { |
| 6254 | Binder.restoreCallingIdentity(identity); |
| 6255 | } |
| 6256 | } |
| 6257 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6258 | } |
| 6259 | |
| 6260 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6261 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6262 | * |
| 6263 | * <p>Requires one of the following permissions: |
| 6264 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6265 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6266 | * privileges. |
| 6267 | * |
| 6268 | * @param subId subscription id |
| 6269 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6270 | * {@code false}. |
| 6271 | */ |
| 6272 | @Override |
| 6273 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6274 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6275 | null /* message */); |
| 6276 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6277 | boolean isEnabled = false; |
| 6278 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6279 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6280 | Phone phone = getPhone(subId); |
| 6281 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6282 | } catch (Exception e) { |
| 6283 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6284 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6285 | } finally { |
| 6286 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6287 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6288 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6289 | } |
| 6290 | |
| 6291 | |
| 6292 | /** |
| 6293 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6294 | * |
| 6295 | * <p> Requires permission: |
| 6296 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6297 | * privileges. |
| 6298 | * |
| 6299 | * @param subId subscription id |
| 6300 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6301 | */ |
| 6302 | @Override |
| 6303 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6304 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6305 | mApp, subId, "setDataRoamingEnabled"); |
| 6306 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6307 | final long identity = Binder.clearCallingIdentity(); |
| 6308 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6309 | Phone phone = getPhone(subId); |
| 6310 | if (phone != null) { |
| 6311 | phone.setDataRoamingEnabled(isEnabled); |
| 6312 | } |
| 6313 | } finally { |
| 6314 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6315 | } |
| 6316 | } |
| 6317 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6318 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6319 | public boolean isManualNetworkSelectionAllowed(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6320 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6321 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6322 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6323 | boolean isAllowed = true; |
| 6324 | final long identity = Binder.clearCallingIdentity(); |
| 6325 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6326 | Phone phone = getPhone(subId); |
| 6327 | if (phone != null) { |
| 6328 | isAllowed = phone.isCspPlmnEnabled(); |
| 6329 | } |
| 6330 | } finally { |
| 6331 | Binder.restoreCallingIdentity(identity); |
| 6332 | } |
| 6333 | return isAllowed; |
| 6334 | } |
| 6335 | |
| 6336 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6337 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6338 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6339 | try { |
| 6340 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6341 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6342 | } catch (SecurityException e) { |
| 6343 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6344 | // has carrier privileges on an active UICC |
| 6345 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6346 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6347 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6348 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6349 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6350 | |
| 6351 | final long identity = Binder.clearCallingIdentity(); |
| 6352 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6353 | UiccController uiccController = UiccController.getInstance(); |
| 6354 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6355 | if (hasReadPermission) { |
| 6356 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6357 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6358 | |
| 6359 | // Remove private info if the caller doesn't have access |
| 6360 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6361 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6362 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6363 | // is available |
| 6364 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6365 | if (card == null || card.getUiccProfile() == null) { |
| 6366 | // assume no access if the card or profile is unavailable |
| 6367 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6368 | continue; |
| 6369 | } |
| 6370 | UiccProfile profile = card.getUiccProfile(); |
| 6371 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6372 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6373 | filteredInfos.add(cardInfo); |
| 6374 | } else { |
| 6375 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6376 | } |
| 6377 | } |
| 6378 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6379 | } finally { |
| 6380 | Binder.restoreCallingIdentity(identity); |
| 6381 | } |
| 6382 | } |
| 6383 | |
| 6384 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6385 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6386 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6387 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6388 | final long identity = Binder.clearCallingIdentity(); |
| 6389 | try { |
| 6390 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6391 | if (slots == null) { |
| 6392 | Rlog.i(LOG_TAG, "slots is null."); |
| 6393 | return null; |
| 6394 | } |
| 6395 | |
| 6396 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6397 | for (int i = 0; i < slots.length; i++) { |
| 6398 | UiccSlot slot = slots[i]; |
| 6399 | if (slot == null) { |
| 6400 | continue; |
| 6401 | } |
| 6402 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6403 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6404 | UiccCard card = slot.getUiccCard(); |
| 6405 | if (card != null) { |
| 6406 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 6407 | } else { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6408 | cardId = slot.getIccId(); |
| 6409 | } |
| 6410 | |
| 6411 | int cardState = 0; |
| 6412 | switch (slot.getCardState()) { |
| 6413 | case CARDSTATE_ABSENT: |
| 6414 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6415 | break; |
| 6416 | case CARDSTATE_PRESENT: |
| 6417 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6418 | break; |
| 6419 | case CARDSTATE_ERROR: |
| 6420 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6421 | break; |
| 6422 | case CARDSTATE_RESTRICTED: |
| 6423 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6424 | break; |
| 6425 | default: |
| 6426 | break; |
| 6427 | |
| 6428 | } |
| 6429 | |
| 6430 | infos[i] = new UiccSlotInfo( |
| 6431 | slot.isActive(), |
| 6432 | slot.isEuicc(), |
| 6433 | cardId, |
| 6434 | cardState, |
| 6435 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6436 | slot.isExtendedApduSupported(), |
| 6437 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6438 | } |
| 6439 | return infos; |
| 6440 | } finally { |
| 6441 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6442 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6443 | } |
| 6444 | |
| 6445 | @Override |
| 6446 | public boolean switchSlots(int[] physicalSlots) { |
| 6447 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6448 | |
| 6449 | final long identity = Binder.clearCallingIdentity(); |
| 6450 | try { |
| 6451 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6452 | } finally { |
| 6453 | Binder.restoreCallingIdentity(identity); |
| 6454 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6455 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6456 | |
| 6457 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6458 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | try { |
| 6461 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6462 | } finally { |
| 6463 | Binder.restoreCallingIdentity(identity); |
| 6464 | } |
| 6465 | } |
| 6466 | |
| 6467 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6468 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6469 | enforceModifyPermission(); |
| 6470 | final Phone phone = getPhone(subId); |
| 6471 | if (phone == null) { |
| 6472 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6473 | return; |
| 6474 | } |
| 6475 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6476 | final long identity = Binder.clearCallingIdentity(); |
| 6477 | try { |
| 6478 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6479 | } finally { |
| 6480 | Binder.restoreCallingIdentity(identity); |
| 6481 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6482 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6483 | |
| 6484 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6485 | * A test API to reload the UICC profile. |
| 6486 | * |
| 6487 | * <p>Requires that the calling app has permission |
| 6488 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6489 | * @hide |
| 6490 | */ |
| 6491 | @Override |
| 6492 | public void refreshUiccProfile(int subId) { |
| 6493 | enforceModifyPermission(); |
| 6494 | |
| 6495 | final long identity = Binder.clearCallingIdentity(); |
| 6496 | try { |
| 6497 | Phone phone = getPhone(subId); |
| 6498 | if (phone == null) { |
| 6499 | return; |
| 6500 | } |
| 6501 | UiccCard uiccCard = phone.getUiccCard(); |
| 6502 | if (uiccCard == null) { |
| 6503 | return; |
| 6504 | } |
| 6505 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6506 | if (uiccProfile == null) { |
| 6507 | return; |
| 6508 | } |
| 6509 | uiccProfile.refresh(); |
| 6510 | } finally { |
| 6511 | Binder.restoreCallingIdentity(identity); |
| 6512 | } |
| 6513 | } |
| 6514 | |
| 6515 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6516 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6517 | */ |
| 6518 | private boolean getDefaultDataEnabled() { |
| 6519 | return "true".equalsIgnoreCase( |
| 6520 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6521 | } |
| 6522 | |
| 6523 | /** |
| 6524 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6525 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6526 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6527 | */ |
| 6528 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6529 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6530 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6531 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6532 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6533 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6534 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6535 | return isDataRoamingEnabled; |
| 6536 | } |
| 6537 | |
| 6538 | /** |
| 6539 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6540 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6541 | */ |
| 6542 | private int getDefaultNetworkType(int subId) { |
| 6543 | return Integer.parseInt( |
| 6544 | TelephonyManager.getTelephonyProperty( |
| 6545 | mSubscriptionController.getPhoneId(subId), |
| 6546 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6547 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6548 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6549 | |
| 6550 | @Override |
| 6551 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6552 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6553 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6554 | |
| 6555 | final long identity = Binder.clearCallingIdentity(); |
| 6556 | try { |
| 6557 | final Phone phone = getPhone(subId); |
| 6558 | if (phone == null) { |
| 6559 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6560 | return; |
| 6561 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6562 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6563 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | } finally { |
| 6565 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6566 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6567 | } |
| 6568 | |
| 6569 | @Override |
| 6570 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6571 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6572 | |
| 6573 | final long identity = Binder.clearCallingIdentity(); |
| 6574 | try { |
| 6575 | final Phone phone = getPhone(subId); |
| 6576 | if (phone == null) { |
| 6577 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6578 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6579 | } |
| 6580 | return phone.getCarrierIdListVersion(); |
| 6581 | } finally { |
| 6582 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6583 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6584 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6585 | |
| 6586 | @Override |
| 6587 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6588 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6589 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6590 | return -1; |
| 6591 | } |
| 6592 | |
| 6593 | final long identity = Binder.clearCallingIdentity(); |
| 6594 | try { |
| 6595 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6596 | } finally { |
| 6597 | Binder.restoreCallingIdentity(identity); |
| 6598 | } |
| 6599 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6600 | |
| 6601 | @Override |
| 6602 | public int getCdmaRoamingMode(int subId) { |
| 6603 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6604 | mApp, subId, "getCdmaRoamingMode"); |
| 6605 | |
| 6606 | final long identity = Binder.clearCallingIdentity(); |
| 6607 | try { |
| 6608 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6609 | } finally { |
| 6610 | Binder.restoreCallingIdentity(identity); |
| 6611 | } |
| 6612 | } |
| 6613 | |
| 6614 | @Override |
| 6615 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6616 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6617 | mApp, subId, "setCdmaRoamingMode"); |
| 6618 | |
| 6619 | final long identity = Binder.clearCallingIdentity(); |
| 6620 | try { |
| 6621 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6622 | } finally { |
| 6623 | Binder.restoreCallingIdentity(identity); |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | @Override |
| 6628 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6630 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6631 | |
| 6632 | final long identity = Binder.clearCallingIdentity(); |
| 6633 | try { |
| 6634 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6635 | } finally { |
| 6636 | Binder.restoreCallingIdentity(identity); |
| 6637 | } |
| 6638 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6639 | |
| 6640 | private void ensureUserRunning(int userId) { |
| 6641 | if (!mUserManager.isUserRunning(userId)) { |
| 6642 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6643 | } |
| 6644 | } |
| 6645 | |
| 6646 | /** |
| 6647 | * Returns a list of SMS apps on a given user. |
| 6648 | * |
| 6649 | * Only the shell user (UID 2000 or 0) can call it. |
| 6650 | * Target user must be running. |
| 6651 | */ |
| 6652 | @Override |
| 6653 | public String[] getSmsApps(int userId) { |
| 6654 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6655 | ensureUserRunning(userId); |
| 6656 | |
| 6657 | final Collection<SmsApplicationData> apps = |
| 6658 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6659 | |
| 6660 | String[] ret = new String[apps.size()]; |
| 6661 | int i = 0; |
| 6662 | for (SmsApplicationData app : apps) { |
| 6663 | ret[i++] = app.mPackageName; |
| 6664 | } |
| 6665 | return ret; |
| 6666 | } |
| 6667 | |
| 6668 | /** |
| 6669 | * Returns the default SMS app package name on a given user. |
| 6670 | * |
| 6671 | * Only the shell user (UID 2000 or 0) can call it. |
| 6672 | * Target user must be running. |
| 6673 | */ |
| 6674 | @Override |
| 6675 | public String getDefaultSmsApp(int userId) { |
| 6676 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6677 | ensureUserRunning(userId); |
| 6678 | |
| 6679 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6680 | /* updateIfNeeded= */ true, userId); |
| 6681 | return cn == null ? null : cn.getPackageName(); |
| 6682 | } |
| 6683 | |
| 6684 | /** |
| 6685 | * Set a package as the default SMS app on a given user. |
| 6686 | * |
| 6687 | * Only the shell user (UID 2000 or 0) can call it. |
| 6688 | * Target user must be running. |
| 6689 | */ |
| 6690 | @Override |
| 6691 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6692 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6693 | ensureUserRunning(userId); |
| 6694 | |
| 6695 | boolean found = false; |
| 6696 | for (String pkg : getSmsApps(userId)) { |
| 6697 | if (TextUtils.equals(packageName, pkg)) { |
| 6698 | found = true; |
| 6699 | break; |
| 6700 | } |
| 6701 | } |
| 6702 | if (!found) { |
| 6703 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6704 | } |
| 6705 | |
| 6706 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6707 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6708 | |
| 6709 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6710 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6711 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6712 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6713 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6714 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6715 | } |
| 6716 | final long identity = Binder.clearCallingIdentity(); |
| 6717 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6718 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6719 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6720 | if (phone.getEmergencyNumberTracker() != null |
| 6721 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6722 | emergencyNumberListInternal.put( |
| 6723 | phone.getSubId(), |
| 6724 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6725 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6726 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6727 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6728 | } finally { |
| 6729 | Binder.restoreCallingIdentity(identity); |
| 6730 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6731 | } |
| 6732 | |
| 6733 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6734 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6735 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6736 | if (!exactMatch) { |
| 6737 | TelephonyPermissions |
| 6738 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6739 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6740 | } |
| 6741 | final long identity = Binder.clearCallingIdentity(); |
| 6742 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6743 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6744 | if (phone.getEmergencyNumberTracker() != null |
| 6745 | && phone.getEmergencyNumberTracker() != null) { |
| 6746 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6747 | number, exactMatch)) { |
| 6748 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6749 | } |
| 6750 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6751 | } |
| 6752 | return false; |
| 6753 | } finally { |
| 6754 | Binder.restoreCallingIdentity(identity); |
| 6755 | } |
| 6756 | } |
| 6757 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6758 | /** |
| 6759 | * Update emergency number list for test mode. |
| 6760 | */ |
| 6761 | @Override |
| 6762 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6763 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6764 | "updateEmergencyNumberListTestMode"); |
| 6765 | |
| 6766 | final long identity = Binder.clearCallingIdentity(); |
| 6767 | try { |
| 6768 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6769 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6770 | if (tracker != null) { |
| 6771 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6772 | } |
| 6773 | } |
| 6774 | } finally { |
| 6775 | Binder.restoreCallingIdentity(identity); |
| 6776 | } |
| 6777 | } |
| 6778 | |
| 6779 | /** |
| 6780 | * Get the full emergency number list for test mode. |
| 6781 | */ |
| 6782 | @Override |
| 6783 | public List<String> getEmergencyNumberListTestMode() { |
| 6784 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6785 | "getEmergencyNumberListTestMode"); |
| 6786 | |
| 6787 | final long identity = Binder.clearCallingIdentity(); |
| 6788 | try { |
| 6789 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6790 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6791 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6792 | if (tracker != null) { |
| 6793 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6794 | emergencyNumbers.add(num.getNumber()); |
| 6795 | } |
| 6796 | } |
| 6797 | } |
| 6798 | return new ArrayList<>(emergencyNumbers); |
| 6799 | } finally { |
| 6800 | Binder.restoreCallingIdentity(identity); |
| 6801 | } |
| 6802 | } |
| 6803 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6804 | @Override |
| 6805 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6806 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6807 | Phone phone = getPhone(subId); |
| 6808 | if (phone == null) { |
| 6809 | return null; |
| 6810 | } |
| 6811 | final long identity = Binder.clearCallingIdentity(); |
| 6812 | try { |
| 6813 | UiccProfile profile = UiccController.getInstance() |
| 6814 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6815 | if (profile != null) { |
| 6816 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6817 | } |
| 6818 | } finally { |
| 6819 | Binder.restoreCallingIdentity(identity); |
| 6820 | } |
| 6821 | return null; |
| 6822 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6823 | |
| 6824 | /** |
| 6825 | * Enable or disable a modem stack. |
| 6826 | */ |
| 6827 | @Override |
| 6828 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6829 | enforceModifyPermission(); |
| 6830 | |
| 6831 | final long identity = Binder.clearCallingIdentity(); |
| 6832 | try { |
| 6833 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6834 | if (phone == null) { |
| 6835 | return false; |
| 6836 | } else { |
| 6837 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6838 | } |
| 6839 | } finally { |
| 6840 | Binder.restoreCallingIdentity(identity); |
| 6841 | } |
| 6842 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6843 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6844 | /** |
| 6845 | * Whether a modem stack is enabled or not. |
| 6846 | */ |
| 6847 | @Override |
| 6848 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 6849 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6850 | if (phone == null) return false; |
| 6851 | |
| 6852 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6853 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 6854 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6855 | } |
| 6856 | |
| 6857 | final long identity = Binder.clearCallingIdentity(); |
| 6858 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 6859 | try { |
| 6860 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 6861 | } catch (NoSuchElementException ex) { |
| 6862 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 6863 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 6864 | } finally { |
| 6865 | Binder.restoreCallingIdentity(identity); |
| 6866 | } |
| 6867 | } |
| 6868 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6869 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6870 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6871 | enforceModifyPermission(); |
| 6872 | |
| 6873 | final long identity = Binder.clearCallingIdentity(); |
| 6874 | try { |
| 6875 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6876 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6877 | .commit(); |
| 6878 | } finally { |
| 6879 | Binder.restoreCallingIdentity(identity); |
| 6880 | } |
| 6881 | } |
| 6882 | |
| 6883 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6884 | @TelephonyManager.IsMultiSimSupportedResult |
| 6885 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6886 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6887 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6888 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6889 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6890 | |
| 6891 | final long identity = Binder.clearCallingIdentity(); |
| 6892 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6893 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6894 | } finally { |
| 6895 | Binder.restoreCallingIdentity(identity); |
| 6896 | } |
| 6897 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6898 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6899 | @TelephonyManager.IsMultiSimSupportedResult |
| 6900 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6901 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6902 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6903 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6904 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 6905 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6906 | } |
| 6907 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6908 | // supported by the modem, indicate that it is restricted. |
| 6909 | PhoneCapability staticCapability = |
| 6910 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6911 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6912 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 6913 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6914 | } |
| 6915 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6916 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 6917 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6918 | } |
| 6919 | // Check if support of multiple SIMs is restricted by carrier |
| 6920 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6921 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6922 | } |
| 6923 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6924 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6925 | } |
| 6926 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6927 | /** |
| 6928 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6929 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6930 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6931 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6932 | * @param numOfSims number of active sims we want to switch to |
| 6933 | */ |
| 6934 | @Override |
| 6935 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6936 | if (numOfSims == 1) { |
| 6937 | enforceModifyPermission(); |
| 6938 | } else { |
| 6939 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6940 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6941 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6942 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6943 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6944 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6945 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6946 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6947 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6948 | return; |
| 6949 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6950 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6951 | } finally { |
| 6952 | Binder.restoreCallingIdentity(identity); |
| 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 6957 | * Get whether making changes to modem configurations will trigger reboot. |
| 6958 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6959 | */ |
| 6960 | @Override |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 6961 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) { |
| 6962 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6963 | mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) { |
| 6964 | return false; |
| 6965 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6966 | final long identity = Binder.clearCallingIdentity(); |
| 6967 | try { |
| 6968 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6969 | } finally { |
| 6970 | Binder.restoreCallingIdentity(identity); |
| 6971 | } |
| 6972 | } |
| 6973 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 6974 | private void updateModemStateMetrics() { |
| 6975 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6976 | // TODO: check the state for each modem if the api is ready. |
| 6977 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6978 | } |
| 6979 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6980 | @Override |
| 6981 | public int[] getSlotsMapping() { |
| 6982 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6983 | |
| 6984 | final long identity = Binder.clearCallingIdentity(); |
| 6985 | try { |
| 6986 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6987 | // All logical slots should have a mapping to a physical slot. |
| 6988 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6989 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6990 | for (int i = 0; i < slotInfos.length; i++) { |
| 6991 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6992 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6993 | } |
| 6994 | } |
| 6995 | return logicalSlotsMapping; |
| 6996 | } finally { |
| 6997 | Binder.restoreCallingIdentity(identity); |
| 6998 | } |
| 6999 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7000 | |
| 7001 | /** |
| 7002 | * Get the IRadio HAL Version |
| 7003 | */ |
| 7004 | @Override |
| 7005 | public int getRadioHalVersion() { |
| 7006 | Phone phone = getDefaultPhone(); |
| 7007 | if (phone == null) return -1; |
| 7008 | HalVersion hv = phone.getHalVersion(); |
| 7009 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7010 | return hv.major * 100 + hv.minor; |
| 7011 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7012 | |
| 7013 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7014 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7015 | * corresponding network requests on a subId. |
| 7016 | * |
| 7017 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7018 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7019 | * 2) APN is un-metered for this subscription, or |
| 7020 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
| 7021 | * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. |
| 7022 | * |
| 7023 | * @return whether data is allowed for a apn type. |
| 7024 | * |
| 7025 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7026 | */ |
| 7027 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7028 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7029 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7030 | mApp, subId, callingPackage, "isDataEnabledForApn")) { |
| 7031 | throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7032 | } |
| 7033 | |
| 7034 | // Now that all security checks passes, perform the operation as ourselves. |
| 7035 | final long identity = Binder.clearCallingIdentity(); |
| 7036 | try { |
| 7037 | Phone phone = getPhone(subId); |
| 7038 | if (phone == null) return false; |
| 7039 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7040 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7041 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7042 | } finally { |
| 7043 | Binder.restoreCallingIdentity(identity); |
| 7044 | } |
| 7045 | } |
| 7046 | |
| 7047 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7048 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7049 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7050 | |
| 7051 | // Now that all security checks passes, perform the operation as ourselves. |
| 7052 | final long identity = Binder.clearCallingIdentity(); |
| 7053 | try { |
| 7054 | Phone phone = getPhone(subId); |
| 7055 | if (phone == null) return true; // By default return true. |
| 7056 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7057 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7058 | } finally { |
| 7059 | Binder.restoreCallingIdentity(identity); |
| 7060 | } |
| 7061 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7062 | |
| 7063 | @Override |
| 7064 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7065 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7066 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7067 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7068 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7069 | } |
| 7070 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7071 | Intent intent = new Intent(); |
| 7072 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7073 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7074 | // Bring up choose default SMS subscription dialog right now |
| 7075 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7076 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7077 | mApp.startActivity(intent); |
| 7078 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7079 | |
| 7080 | @Override |
| 7081 | public String getMmsUAProfUrl(int subId) { |
| 7082 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7083 | final long identity = Binder.clearCallingIdentity(); |
| 7084 | try { |
| 7085 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7086 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7087 | } finally { |
| 7088 | Binder.restoreCallingIdentity(identity); |
| 7089 | } |
| 7090 | } |
| 7091 | |
| 7092 | @Override |
| 7093 | public String getMmsUserAgent(int subId) { |
| 7094 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7095 | final long identity = Binder.clearCallingIdentity(); |
| 7096 | try { |
| 7097 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7098 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7099 | } finally { |
| 7100 | Binder.restoreCallingIdentity(identity); |
| 7101 | } |
| 7102 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7103 | |
| 7104 | @Override |
| 7105 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7106 | enforceModifyPermission(); |
| 7107 | |
| 7108 | // Now that all security checks passes, perform the operation as ourselves. |
| 7109 | final long identity = Binder.clearCallingIdentity(); |
| 7110 | try { |
| 7111 | Phone phone = getPhone(subId); |
| 7112 | if (phone == null) return false; |
| 7113 | |
| 7114 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7115 | } finally { |
| 7116 | Binder.restoreCallingIdentity(identity); |
| 7117 | } |
| 7118 | } |
| 7119 | |
| 7120 | @Override |
| 7121 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7122 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7123 | |
| 7124 | // Now that all security checks passes, perform the operation as ourselves. |
| 7125 | final long identity = Binder.clearCallingIdentity(); |
| 7126 | try { |
| 7127 | Phone phone = getPhone(subId); |
| 7128 | if (phone == null) return false; |
| 7129 | |
| 7130 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7131 | } finally { |
| 7132 | Binder.restoreCallingIdentity(identity); |
| 7133 | } |
| 7134 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7135 | } |