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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 24 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 25 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 26 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 27 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 30 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 31 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 32 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 33 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 34 | import android.content.pm.PackageManager; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 35 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.net.Uri; |
| 37 | import android.os.AsyncResult; |
| 38 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 39 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.os.Bundle; |
| 41 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 42 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.os.Looper; |
| 44 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 45 | import android.os.Messenger; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 46 | import android.os.PersistableBundle; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 47 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 48 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.os.ServiceManager; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 50 | import android.os.ShellCallback; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 51 | import android.os.SystemProperties; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 53 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 54 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 55 | import android.preference.PreferenceManager; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 56 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 57 | import android.provider.Telephony; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 58 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 59 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 60 | import android.telecom.TelecomManager; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 61 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 62 | import android.telephony.CarrierRestrictionRules; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 64 | import android.telephony.CellInfoGsm; |
| 65 | import android.telephony.CellInfoWcdma; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 66 | import android.telephony.CellLocation; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 67 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 68 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 69 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 70 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 71 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 72 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 73 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 74 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 75 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 76 | import android.telephony.RadioAccessFamily; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 77 | import android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 78 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 79 | import android.telephony.SignalStrength; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 80 | import android.telephony.SmsManager; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 81 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 82 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 83 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 84 | import android.telephony.TelephonyManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 85 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 86 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 87 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 88 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 89 | import android.telephony.cdma.CdmaCellLocation; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 90 | import android.telephony.data.ApnSetting; |
| 91 | import android.telephony.emergency.EmergencyNumber; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 92 | import android.telephony.gsm.GsmCellLocation; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 93 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 94 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 95 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 96 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 97 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 98 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 99 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 100 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 101 | import android.telephony.ims.feature.MmTelFeature; |
| 102 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 103 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 105 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 106 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 107 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 108 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 109 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import com.android.ims.ImsException; |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 111 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 112 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 113 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 114 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 115 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 116 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 117 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 118 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 120 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 121 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.LocaleTracker; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 125 | import com.android.internal.telephony.MccTable; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.ServiceStateTracker; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.SmsApplication; |
| 138 | import com.android.internal.telephony.SmsApplication.SmsApplicationData; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.TelephonyPermissions; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.uicc.IccIoResult; |
| 146 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 152 | import com.android.internal.telephony.uicc.UiccSlot; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 154 | import com.android.internal.util.HexDump; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 155 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 156 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 157 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 158 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 159 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 160 | import java.io.FileDescriptor; |
| 161 | import java.io.PrintWriter; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 162 | import java.nio.charset.StandardCharsets; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 163 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 164 | import java.util.Arrays; |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 165 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 166 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 167 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 168 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 169 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 170 | import java.util.Map; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 171 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | |
| 173 | /** |
| 174 | * Implementation of the ITelephony interface. |
| 175 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 176 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 177 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 178 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 179 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 180 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 181 | |
| 182 | // Message codes used with mMainThreadHandler |
| 183 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 184 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 185 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 186 | private static final int CMD_OPEN_CHANNEL = 9; |
| 187 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 188 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 189 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 190 | private static final int CMD_NV_READ_ITEM = 13; |
| 191 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 192 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 193 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 194 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 195 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 196 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 197 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 198 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 199 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 200 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 201 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 202 | private static final int CMD_SEND_ENVELOPE = 25; |
| 203 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 204 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 205 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 206 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 207 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 208 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 209 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 210 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 211 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 212 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 213 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 214 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 215 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 216 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 217 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 218 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 219 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 220 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 221 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 222 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 223 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 224 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 225 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 226 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 227 | private static final int CMD_SWITCH_SLOTS = 50; |
| 228 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 229 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 230 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 231 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 232 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 233 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 234 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 235 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 236 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 237 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 238 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 239 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 240 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 241 | private static final int CMD_MODEM_REBOOT = 64; |
| 242 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 243 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 244 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 245 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 246 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 247 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 248 | // Parameters of select command. |
| 249 | private static final int SELECT_COMMAND = 0xA4; |
| 250 | private static final int SELECT_P1 = 0x04; |
| 251 | private static final int SELECT_P2 = 0; |
| 252 | private static final int SELECT_P3 = 0x10; |
| 253 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 254 | private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network"; |
| 255 | private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming"; |
| 256 | private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata"; |
| 257 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 258 | /** The singleton instance. */ |
| 259 | private static PhoneInterfaceManager sInstance; |
| 260 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 261 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 262 | private CallManager mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 263 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 264 | private AppOpsManager mAppOps; |
| 265 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 266 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 267 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 268 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 270 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 271 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 272 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 273 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 274 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 275 | // String to store multi SIM allowed |
| 276 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 277 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 278 | // The AID of ISD-R. |
| 279 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 280 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 281 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 282 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 283 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 284 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 285 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 286 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 287 | * A request object to use for transmitting data to an ICC. |
| 288 | */ |
| 289 | private static final class IccAPDUArgument { |
| 290 | public int channel, cla, command, p1, p2, p3; |
| 291 | public String data; |
| 292 | |
| 293 | public IccAPDUArgument(int channel, int cla, int command, |
| 294 | int p1, int p2, int p3, String data) { |
| 295 | this.channel = channel; |
| 296 | this.cla = cla; |
| 297 | this.command = command; |
| 298 | this.p1 = p1; |
| 299 | this.p2 = p2; |
| 300 | this.p3 = p3; |
| 301 | this.data = data; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 306 | * A request object to use for transmitting data to an ICC. |
| 307 | */ |
| 308 | private static final class ManualNetworkSelectionArgument { |
| 309 | public OperatorInfo operatorInfo; |
| 310 | public boolean persistSelection; |
| 311 | |
| 312 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 313 | this.operatorInfo = operatorInfo; |
| 314 | this.persistSelection = persistSelection; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 319 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 320 | * request after sending. The main thread will notify the request when it is complete. |
| 321 | */ |
| 322 | private static final class MainThreadRequest { |
| 323 | /** The argument to use for the request */ |
| 324 | public Object argument; |
| 325 | /** The result of the request that is run on the main thread */ |
| 326 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 327 | // The subscriber id that this request applies to. Defaults to |
| 328 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 329 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 331 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 332 | public Phone phone; |
| 333 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 334 | public WorkSource workSource; |
| 335 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 336 | public MainThreadRequest(Object argument) { |
| 337 | this.argument = argument; |
| 338 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 339 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 340 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 341 | this.argument = argument; |
| 342 | if (phone != null) { |
| 343 | this.phone = phone; |
| 344 | } |
| 345 | this.workSource = workSource; |
| 346 | } |
| 347 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 348 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 349 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 350 | if (subId != null) { |
| 351 | this.subId = subId; |
| 352 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 353 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 354 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 357 | private static final class IncomingThirdPartyCallArgs { |
| 358 | public final ComponentName component; |
| 359 | public final String callId; |
| 360 | public final String callerDisplayName; |
| 361 | |
| 362 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 363 | String callerDisplayName) { |
| 364 | this.component = component; |
| 365 | this.callId = callId; |
| 366 | this.callerDisplayName = callerDisplayName; |
| 367 | } |
| 368 | } |
| 369 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | /** |
| 371 | * A handler that processes messages on the main thread in the phone process. Since many |
| 372 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 373 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 374 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 375 | * on, which will be notified when the operation completes and will contain the result of the |
| 376 | * request. |
| 377 | * |
| 378 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 379 | * note that request.result must be set to something non-null for the calling thread to |
| 380 | * unblock. |
| 381 | */ |
| 382 | private final class MainThreadHandler extends Handler { |
| 383 | @Override |
| 384 | public void handleMessage(Message msg) { |
| 385 | MainThreadRequest request; |
| 386 | Message onCompleted; |
| 387 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 388 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 389 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 390 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | |
| 392 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 393 | case CMD_HANDLE_USSD_REQUEST: { |
| 394 | request = (MainThreadRequest) msg.obj; |
| 395 | final Phone phone = getPhoneFromRequest(request); |
| 396 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 397 | String ussdRequest = ussdObject.first; |
| 398 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 399 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 400 | if (!isUssdApiAllowed(request.subId)) { |
| 401 | // Carrier does not support use of this API, return failure. |
| 402 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 403 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 404 | Bundle returnData = new Bundle(); |
| 405 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 406 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 407 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 408 | request.result = true; |
| 409 | notifyRequester(request); |
| 410 | return; |
| 411 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 412 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 413 | try { |
| 414 | request.result = phone != null |
| 415 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 416 | } catch (CallStateException cse) { |
| 417 | request.result = false; |
| 418 | } |
| 419 | // Wake up the requesting thread |
| 420 | notifyRequester(request); |
| 421 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 424 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 426 | final Phone phone = getPhoneFromRequest(request); |
| 427 | request.result = phone != null ? |
| 428 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 429 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 430 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 431 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 433 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 435 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 436 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 437 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 438 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 439 | if (uiccCard == null) { |
| 440 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 441 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 442 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 443 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 444 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 445 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 446 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 447 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 448 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 449 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 450 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 451 | break; |
| 452 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 453 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 454 | ar = (AsyncResult) msg.obj; |
| 455 | request = (MainThreadRequest) ar.userObj; |
| 456 | if (ar.exception == null && ar.result != null) { |
| 457 | request.result = ar.result; |
| 458 | } else { |
| 459 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 460 | if (ar.result == null) { |
| 461 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 462 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 463 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 464 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 465 | } else { |
| 466 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 467 | } |
| 468 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 469 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 470 | break; |
| 471 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 472 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 473 | request = (MainThreadRequest) msg.obj; |
| 474 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 475 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 476 | if (uiccCard == null) { |
| 477 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 478 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 479 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | } else { |
| 481 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 482 | request); |
| 483 | uiccCard.iccTransmitApduBasicChannel( |
| 484 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 485 | iccArgument.p3, iccArgument.data, onCompleted); |
| 486 | } |
| 487 | break; |
| 488 | |
| 489 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 490 | ar = (AsyncResult) msg.obj; |
| 491 | request = (MainThreadRequest) ar.userObj; |
| 492 | if (ar.exception == null && ar.result != null) { |
| 493 | request.result = ar.result; |
| 494 | } else { |
| 495 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 496 | if (ar.result == null) { |
| 497 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 498 | } else if (ar.exception instanceof CommandException) { |
| 499 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 500 | ar.exception); |
| 501 | } else { |
| 502 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 503 | } |
| 504 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 505 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 506 | break; |
| 507 | |
| 508 | case CMD_EXCHANGE_SIM_IO: |
| 509 | request = (MainThreadRequest) msg.obj; |
| 510 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 511 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 512 | if (uiccCard == null) { |
| 513 | loge("iccExchangeSimIO: No UICC"); |
| 514 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
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 | } else { |
| 517 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 518 | request); |
| 519 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 520 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 521 | iccArgument.data, onCompleted); |
| 522 | } |
| 523 | break; |
| 524 | |
| 525 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 526 | ar = (AsyncResult) msg.obj; |
| 527 | request = (MainThreadRequest) ar.userObj; |
| 528 | if (ar.exception == null && ar.result != null) { |
| 529 | request.result = ar.result; |
| 530 | } else { |
| 531 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 532 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | break; |
| 535 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 536 | case CMD_SEND_ENVELOPE: |
| 537 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 538 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 539 | if (uiccCard == null) { |
| 540 | loge("sendEnvelopeWithStatus: No UICC"); |
| 541 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 542 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 543 | } else { |
| 544 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 545 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 546 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 547 | break; |
| 548 | |
| 549 | case EVENT_SEND_ENVELOPE_DONE: |
| 550 | ar = (AsyncResult) msg.obj; |
| 551 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 552 | if (ar.exception == null && ar.result != null) { |
| 553 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 554 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 555 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 556 | if (ar.result == null) { |
| 557 | loge("sendEnvelopeWithStatus: Empty response"); |
| 558 | } else if (ar.exception instanceof CommandException) { |
| 559 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 560 | ar.exception); |
| 561 | } else { |
| 562 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 563 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 564 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 565 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 566 | break; |
| 567 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 568 | case CMD_OPEN_CHANNEL: |
| 569 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 570 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 571 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 572 | if (uiccCard == null) { |
| 573 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 574 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 575 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 576 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 577 | } else { |
| 578 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 579 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 580 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 581 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 582 | break; |
| 583 | |
| 584 | case EVENT_OPEN_CHANNEL_DONE: |
| 585 | ar = (AsyncResult) msg.obj; |
| 586 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 588 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 589 | int[] result = (int[]) ar.result; |
| 590 | int channelId = result[0]; |
| 591 | byte[] selectResponse = null; |
| 592 | if (result.length > 1) { |
| 593 | selectResponse = new byte[result.length - 1]; |
| 594 | for (int i = 1; i < result.length; ++i) { |
| 595 | selectResponse[i - 1] = (byte) result[i]; |
| 596 | } |
| 597 | } |
| 598 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 599 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 600 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 601 | if (ar.result == null) { |
| 602 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 604 | if (ar.exception != null) { |
| 605 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 606 | } |
| 607 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 608 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 609 | if (ar.exception instanceof CommandException) { |
| 610 | CommandException.Error error = |
| 611 | ((CommandException) (ar.exception)).getCommandError(); |
| 612 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 613 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 614 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 615 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 619 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 621 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 622 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 623 | break; |
| 624 | |
| 625 | case CMD_CLOSE_CHANNEL: |
| 626 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 627 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 628 | if (uiccCard == null) { |
| 629 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 630 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 631 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 632 | } else { |
| 633 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 634 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 635 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | break; |
| 637 | |
| 638 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 639 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 640 | break; |
| 641 | |
| 642 | case CMD_NV_READ_ITEM: |
| 643 | request = (MainThreadRequest) msg.obj; |
| 644 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 645 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 646 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 647 | break; |
| 648 | |
| 649 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | ar = (AsyncResult) msg.obj; |
| 651 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 652 | if (ar.exception == null && ar.result != null) { |
| 653 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 655 | request.result = ""; |
| 656 | if (ar.result == null) { |
| 657 | loge("nvReadItem: Empty response"); |
| 658 | } else if (ar.exception instanceof CommandException) { |
| 659 | loge("nvReadItem: CommandException: " + |
| 660 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | } |
| 664 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 665 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | break; |
| 667 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 668 | case CMD_NV_WRITE_ITEM: |
| 669 | request = (MainThreadRequest) msg.obj; |
| 670 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 671 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 672 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 673 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 674 | break; |
| 675 | |
| 676 | case EVENT_NV_WRITE_ITEM_DONE: |
| 677 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 678 | break; |
| 679 | |
| 680 | case CMD_NV_WRITE_CDMA_PRL: |
| 681 | request = (MainThreadRequest) msg.obj; |
| 682 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 683 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 684 | break; |
| 685 | |
| 686 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 687 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 688 | break; |
| 689 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 690 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 691 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 692 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 693 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | break; |
| 695 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 696 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 697 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 700 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 701 | request = (MainThreadRequest) msg.obj; |
| 702 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 703 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 704 | break; |
| 705 | |
| 706 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 707 | ar = (AsyncResult) msg.obj; |
| 708 | request = (MainThreadRequest) ar.userObj; |
| 709 | if (ar.exception == null && ar.result != null) { |
| 710 | request.result = ar.result; // Integer |
| 711 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 712 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 713 | if (ar.result == null) { |
| 714 | loge("getPreferredNetworkType: Empty response"); |
| 715 | } else if (ar.exception instanceof CommandException) { |
| 716 | loge("getPreferredNetworkType: CommandException: " + |
| 717 | ar.exception); |
| 718 | } else { |
| 719 | loge("getPreferredNetworkType: Unknown exception"); |
| 720 | } |
| 721 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 722 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 723 | break; |
| 724 | |
| 725 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 726 | request = (MainThreadRequest) msg.obj; |
| 727 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 728 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 729 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 733 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 734 | break; |
| 735 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 736 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 737 | request = (MainThreadRequest)msg.obj; |
| 738 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 739 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 740 | break; |
| 741 | |
| 742 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 743 | ar = (AsyncResult)msg.obj; |
| 744 | request = (MainThreadRequest)ar.userObj; |
| 745 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 746 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 747 | break; |
| 748 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 749 | case CMD_SET_VOICEMAIL_NUMBER: |
| 750 | request = (MainThreadRequest) msg.obj; |
| 751 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 752 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 753 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 754 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 758 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 759 | break; |
| 760 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 761 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 762 | request = (MainThreadRequest) msg.obj; |
| 763 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 764 | request); |
| 765 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 766 | break; |
| 767 | |
| 768 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 769 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 770 | break; |
| 771 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 772 | case CMD_PERFORM_NETWORK_SCAN: |
| 773 | request = (MainThreadRequest) msg.obj; |
| 774 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 775 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 776 | break; |
| 777 | |
| 778 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 779 | ar = (AsyncResult) msg.obj; |
| 780 | request = (MainThreadRequest) ar.userObj; |
| 781 | CellNetworkScanResult cellScanResult; |
| 782 | if (ar.exception == null && ar.result != null) { |
| 783 | cellScanResult = new CellNetworkScanResult( |
| 784 | CellNetworkScanResult.STATUS_SUCCESS, |
| 785 | (List<OperatorInfo>) ar.result); |
| 786 | } else { |
| 787 | if (ar.result == null) { |
| 788 | loge("getCellNetworkScanResults: Empty response"); |
| 789 | } |
| 790 | if (ar.exception != null) { |
| 791 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 792 | } |
| 793 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 794 | if (ar.exception instanceof CommandException) { |
| 795 | CommandException.Error error = |
| 796 | ((CommandException) (ar.exception)).getCommandError(); |
| 797 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 798 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 799 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 800 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 801 | } |
| 802 | } |
| 803 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 804 | } |
| 805 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 806 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 807 | break; |
| 808 | |
| 809 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 810 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 811 | ManualNetworkSelectionArgument selArg = |
| 812 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 813 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 814 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 815 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 816 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 817 | break; |
| 818 | |
| 819 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 820 | ar = (AsyncResult) msg.obj; |
| 821 | request = (MainThreadRequest) ar.userObj; |
| 822 | if (ar.exception == null) { |
| 823 | request.result = true; |
| 824 | } else { |
| 825 | request.result = false; |
| 826 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 827 | } |
| 828 | notifyRequester(request); |
| 829 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 830 | break; |
| 831 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 832 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 833 | request = (MainThreadRequest) msg.obj; |
| 834 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 835 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 839 | ar = (AsyncResult) msg.obj; |
| 840 | request = (MainThreadRequest) ar.userObj; |
| 841 | if (ar.exception == null && ar.result != null) { |
| 842 | request.result = ar.result; |
| 843 | } else { |
| 844 | if (ar.result == null) { |
| 845 | loge("queryModemActivityInfo: Empty response"); |
| 846 | } else if (ar.exception instanceof CommandException) { |
| 847 | loge("queryModemActivityInfo: CommandException: " + |
| 848 | ar.exception); |
| 849 | } else { |
| 850 | loge("queryModemActivityInfo: Unknown exception"); |
| 851 | } |
| 852 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 853 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 854 | if (request.result == null) { |
| 855 | request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0); |
| 856 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 857 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 858 | break; |
| 859 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 860 | case CMD_SET_ALLOWED_CARRIERS: |
| 861 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 862 | CarrierRestrictionRules argument = |
| 863 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 864 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 865 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 866 | break; |
| 867 | |
| 868 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 869 | ar = (AsyncResult) msg.obj; |
| 870 | request = (MainThreadRequest) ar.userObj; |
| 871 | if (ar.exception == null && ar.result != null) { |
| 872 | request.result = ar.result; |
| 873 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 874 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 875 | if (ar.exception instanceof CommandException) { |
| 876 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 877 | CommandException.Error error = |
| 878 | ((CommandException) (ar.exception)).getCommandError(); |
| 879 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 880 | request.result = |
| 881 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 882 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 883 | } else { |
| 884 | loge("setAllowedCarriers: Unknown exception"); |
| 885 | } |
| 886 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 887 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case CMD_GET_ALLOWED_CARRIERS: |
| 891 | request = (MainThreadRequest) msg.obj; |
| 892 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 893 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 897 | ar = (AsyncResult) msg.obj; |
| 898 | request = (MainThreadRequest) ar.userObj; |
| 899 | if (ar.exception == null && ar.result != null) { |
| 900 | request.result = ar.result; |
| 901 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 902 | request.result = new IllegalStateException( |
| 903 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 904 | if (ar.result == null) { |
| 905 | loge("getAllowedCarriers: Empty response"); |
| 906 | } else if (ar.exception instanceof CommandException) { |
| 907 | loge("getAllowedCarriers: CommandException: " + |
| 908 | ar.exception); |
| 909 | } else { |
| 910 | loge("getAllowedCarriers: Unknown exception"); |
| 911 | } |
| 912 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 913 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 914 | break; |
| 915 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 916 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 917 | ar = (AsyncResult) msg.obj; |
| 918 | request = (MainThreadRequest) ar.userObj; |
| 919 | if (ar.exception == null && ar.result != null) { |
| 920 | request.result = ar.result; |
| 921 | } else { |
| 922 | request.result = new IllegalArgumentException( |
| 923 | "Failed to retrieve Forbidden Plmns"); |
| 924 | if (ar.result == null) { |
| 925 | loge("getForbiddenPlmns: Empty response"); |
| 926 | } else { |
| 927 | loge("getForbiddenPlmns: Unknown exception"); |
| 928 | } |
| 929 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 930 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 931 | break; |
| 932 | |
| 933 | case CMD_GET_FORBIDDEN_PLMNS: |
| 934 | request = (MainThreadRequest) msg.obj; |
| 935 | uiccCard = getUiccCardFromRequest(request); |
| 936 | if (uiccCard == null) { |
| 937 | loge("getForbiddenPlmns() UiccCard is null"); |
| 938 | request.result = new IllegalArgumentException( |
| 939 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 940 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 941 | break; |
| 942 | } |
| 943 | Integer appType = (Integer) request.argument; |
| 944 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 945 | if (uiccApp == null) { |
| 946 | loge("getForbiddenPlmns() no app with specified type -- " |
| 947 | + appType); |
| 948 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 949 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 950 | break; |
| 951 | } else { |
| 952 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 953 | + " specified type -- " + appType); |
| 954 | } |
| 955 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 956 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 957 | onCompleted); |
| 958 | break; |
| 959 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 960 | case CMD_SWITCH_SLOTS: |
| 961 | request = (MainThreadRequest) msg.obj; |
| 962 | int[] physicalSlots = (int[]) request.argument; |
| 963 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 964 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 965 | break; |
| 966 | |
| 967 | case EVENT_SWITCH_SLOTS_DONE: |
| 968 | ar = (AsyncResult) msg.obj; |
| 969 | request = (MainThreadRequest) ar.userObj; |
| 970 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 971 | notifyRequester(request); |
| 972 | break; |
| 973 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 974 | request = (MainThreadRequest) msg.obj; |
| 975 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 976 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 977 | break; |
| 978 | |
| 979 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 980 | ar = (AsyncResult) msg.obj; |
| 981 | request = (MainThreadRequest) ar.userObj; |
| 982 | if (ar.exception != null) { |
| 983 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 984 | } else { |
| 985 | int mode = ((int[]) ar.result)[0]; |
| 986 | if (mode == 0) { |
| 987 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 988 | } else { |
| 989 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 990 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 991 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 992 | notifyRequester(request); |
| 993 | break; |
| 994 | case CMD_GET_CDMA_ROAMING_MODE: |
| 995 | request = (MainThreadRequest) msg.obj; |
| 996 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 997 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 998 | break; |
| 999 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1000 | ar = (AsyncResult) msg.obj; |
| 1001 | request = (MainThreadRequest) ar.userObj; |
| 1002 | if (ar.exception != null) { |
| 1003 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1004 | } else { |
| 1005 | request.result = ((int[]) ar.result)[0]; |
| 1006 | } |
| 1007 | notifyRequester(request); |
| 1008 | break; |
| 1009 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1010 | request = (MainThreadRequest) msg.obj; |
| 1011 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1012 | int mode = (int) request.argument; |
| 1013 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1014 | break; |
| 1015 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1016 | ar = (AsyncResult) msg.obj; |
| 1017 | request = (MainThreadRequest) ar.userObj; |
| 1018 | request.result = ar.exception == null; |
| 1019 | notifyRequester(request); |
| 1020 | break; |
| 1021 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1022 | request = (MainThreadRequest) msg.obj; |
| 1023 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1024 | int subscriptionMode = (int) request.argument; |
| 1025 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1026 | break; |
| 1027 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1028 | ar = (AsyncResult) msg.obj; |
| 1029 | request = (MainThreadRequest) ar.userObj; |
| 1030 | request.result = ar.exception == null; |
| 1031 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1032 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1033 | case CMD_GET_ALL_CELL_INFO: |
| 1034 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1035 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1036 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1037 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1038 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1039 | ar = (AsyncResult) msg.obj; |
| 1040 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1041 | // If a timeout occurs, the response will be null |
| 1042 | request.result = (ar.exception == null && ar.result != null) |
| 1043 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1044 | synchronized (request) { |
| 1045 | request.notifyAll(); |
| 1046 | } |
| 1047 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1048 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1049 | request = (MainThreadRequest) msg.obj; |
| 1050 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1051 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1052 | break; |
| 1053 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1054 | ar = (AsyncResult) msg.obj; |
| 1055 | request = (MainThreadRequest) ar.userObj; |
| 1056 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1057 | try { |
| 1058 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1059 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1060 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1061 | new android.os.ParcelableException(ar.exception)); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1062 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1063 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Nathan Harold | e82c4b8 | 2018-12-18 19:40:37 -0800 | [diff] [blame] | 1064 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1065 | } else { |
| 1066 | // use the result as returned |
| 1067 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1068 | } |
| 1069 | } catch (RemoteException re) { |
| 1070 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1071 | } |
| 1072 | break; |
| 1073 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1074 | request = (MainThreadRequest) msg.obj; |
| 1075 | WorkSource ws = (WorkSource) request.argument; |
| 1076 | Phone phone = getPhoneFromRequest(request); |
| 1077 | phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
| 1078 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1079 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1080 | ar = (AsyncResult) msg.obj; |
| 1081 | request = (MainThreadRequest) ar.userObj; |
| 1082 | if (ar.exception == null) { |
| 1083 | request.result = ar.result; |
| 1084 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1085 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1086 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 1087 | ? new CdmaCellLocation() : new GsmCellLocation(); |
| 1088 | } |
| 1089 | |
| 1090 | synchronized (request) { |
| 1091 | request.notifyAll(); |
| 1092 | } |
| 1093 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1094 | case CMD_MODEM_REBOOT: |
| 1095 | request = (MainThreadRequest) msg.obj; |
| 1096 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1097 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1098 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1099 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1100 | handleNullReturnEvent(msg, "rebootModem"); |
| 1101 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1102 | case CMD_REQUEST_ENABLE_MODEM: |
| 1103 | request = (MainThreadRequest) msg.obj; |
| 1104 | boolean enable = (boolean) request.argument; |
| 1105 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1106 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1107 | PhoneConfigurationManager.getInstance() |
| 1108 | .enablePhone(request.phone, enable, onCompleted); |
| 1109 | break; |
| 1110 | case EVENT_ENABLE_MODEM_DONE: |
| 1111 | ar = (AsyncResult) msg.obj; |
| 1112 | request = (MainThreadRequest) ar.userObj; |
| 1113 | request.result = (ar.exception == null); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1114 | //update the cache as modem status has changed |
| 1115 | mPhoneConfigurationManager.addToPhoneStatusCache( |
| 1116 | request.phone.getPhoneId(), msg.arg1 == 1); |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1117 | updateModemStateMetrics(); |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1118 | notifyRequester(request); |
| 1119 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1120 | default: |
| 1121 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1122 | break; |
| 1123 | } |
| 1124 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1125 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1126 | private void notifyRequester(MainThreadRequest request) { |
| 1127 | synchronized (request) { |
| 1128 | request.notifyAll(); |
| 1129 | } |
| 1130 | } |
| 1131 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1132 | private void handleNullReturnEvent(Message msg, String command) { |
| 1133 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1134 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1135 | if (ar.exception == null) { |
| 1136 | request.result = true; |
| 1137 | } else { |
| 1138 | request.result = false; |
| 1139 | if (ar.exception instanceof CommandException) { |
| 1140 | loge(command + ": CommandException: " + ar.exception); |
| 1141 | } else { |
| 1142 | loge(command + ": Unknown exception"); |
| 1143 | } |
| 1144 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1145 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1146 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * Posts the specified command to be executed on the main thread, |
| 1151 | * waits for the request to complete, and returns the result. |
| 1152 | * @see #sendRequestAsync |
| 1153 | */ |
| 1154 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1155 | return sendRequest( |
| 1156 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Posts the specified command to be executed on the main thread, |
| 1161 | * waits for the request to complete, and returns the result. |
| 1162 | * @see #sendRequestAsync |
| 1163 | */ |
| 1164 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1165 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1166 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | /** |
| 1170 | * Posts the specified command to be executed on the main thread, |
| 1171 | * waits for the request to complete, and returns the result. |
| 1172 | * @see #sendRequestAsync |
| 1173 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1174 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1175 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * Posts the specified command to be executed on the main thread, |
| 1180 | * waits for the request to complete, and returns the result. |
| 1181 | * @see #sendRequestAsync |
| 1182 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1183 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1184 | return sendRequest(command, argument, subId, null, workSource); |
| 1185 | } |
| 1186 | |
| 1187 | /** |
| 1188 | * Posts the specified command to be executed on the main thread, |
| 1189 | * waits for the request to complete, and returns the result. |
| 1190 | * @see #sendRequestAsync |
| 1191 | */ |
| 1192 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1193 | return sendRequest( |
| 1194 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * Posts the specified command to be executed on the main thread, |
| 1199 | * waits for the request to complete, and returns the result. |
| 1200 | * @see #sendRequestAsync |
| 1201 | */ |
| 1202 | private Object sendRequest( |
| 1203 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1204 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1205 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1206 | } |
| 1207 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1208 | MainThreadRequest request = null; |
| 1209 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1210 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1211 | } else if (phone != null) { |
| 1212 | request = new MainThreadRequest(argument, phone, workSource); |
| 1213 | } else { |
| 1214 | request = new MainThreadRequest(argument, subId, workSource); |
| 1215 | } |
| 1216 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1217 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1218 | msg.sendToTarget(); |
| 1219 | |
| 1220 | // Wait for the request to complete |
| 1221 | synchronized (request) { |
| 1222 | while (request.result == null) { |
| 1223 | try { |
| 1224 | request.wait(); |
| 1225 | } catch (InterruptedException e) { |
| 1226 | // Do nothing, go back and wait until the request is complete |
| 1227 | } |
| 1228 | } |
| 1229 | } |
| 1230 | return request.result; |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1235 | * Posts the specified command to be executed on the main thread, and |
| 1236 | * returns immediately. |
| 1237 | * @see #sendRequest |
| 1238 | */ |
| 1239 | private void sendRequestAsync(int command) { |
| 1240 | mMainThreadHandler.sendEmptyMessage(command); |
| 1241 | } |
| 1242 | |
| 1243 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1244 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1245 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1246 | */ |
| 1247 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1248 | sendRequestAsync(command, argument, null, null); |
| 1249 | } |
| 1250 | |
| 1251 | /** |
| 1252 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1253 | * @see {@link #sendRequest(int,Object)} |
| 1254 | */ |
| 1255 | private void sendRequestAsync( |
| 1256 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1257 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1258 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1259 | msg.sendToTarget(); |
| 1260 | } |
| 1261 | |
| 1262 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1263 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1264 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1265 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1266 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1267 | synchronized (PhoneInterfaceManager.class) { |
| 1268 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1269 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1270 | } else { |
| 1271 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1272 | } |
| 1273 | return sInstance; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1278 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1279 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1280 | mCM = PhoneGlobals.getInstance().mCM; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1281 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1282 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1283 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1284 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1285 | mTelephonySharedPreferences = |
| 1286 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1287 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1288 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1289 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1290 | publish(); |
| 1291 | } |
| 1292 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1293 | private Phone getDefaultPhone() { |
| 1294 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1295 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1296 | } |
| 1297 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1298 | private void publish() { |
| 1299 | if (DBG) log("publish: " + this); |
| 1300 | |
| 1301 | ServiceManager.addService("phone", this); |
| 1302 | } |
| 1303 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1304 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1305 | if (request.phone != null) { |
| 1306 | return request.phone; |
| 1307 | } else { |
| 1308 | return getPhoneFromSubId(request.subId); |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | private Phone getPhoneFromSubId(int subId) { |
| 1313 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1314 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1315 | } |
| 1316 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1317 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1318 | Phone phone = getPhoneFromRequest(request); |
| 1319 | return phone == null ? null : |
| 1320 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1321 | } |
| 1322 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1323 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1324 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1325 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1326 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1327 | |
| 1328 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1329 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1332 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1333 | if (DBG) log("dial: " + number); |
| 1334 | // No permission check needed here: This is just a wrapper around the |
| 1335 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1336 | // the UI before it does anything. |
| 1337 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1338 | final long identity = Binder.clearCallingIdentity(); |
| 1339 | try { |
| 1340 | String url = createTelUrl(number); |
| 1341 | if (url == null) { |
| 1342 | return; |
| 1343 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1344 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1345 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1346 | PhoneConstants.State state = mCM.getState(subId); |
| 1347 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1348 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1349 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1350 | mApp.startActivity(intent); |
| 1351 | } |
| 1352 | } finally { |
| 1353 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1358 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1361 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1362 | if (DBG) log("call: " + number); |
| 1363 | |
| 1364 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1365 | // need to do a permission check since we're calling startActivity() |
| 1366 | // from the context of the phone app. |
| 1367 | enforceCallPermission(); |
| 1368 | |
| 1369 | if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
| 1370 | != AppOpsManager.MODE_ALLOWED) { |
| 1371 | return; |
| 1372 | } |
| 1373 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1374 | final long identity = Binder.clearCallingIdentity(); |
| 1375 | try { |
| 1376 | String url = createTelUrl(number); |
| 1377 | if (url == null) { |
| 1378 | return; |
| 1379 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1380 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1381 | boolean isValid = false; |
| 1382 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1383 | if (slist != null) { |
| 1384 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1385 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1386 | isValid = true; |
| 1387 | break; |
| 1388 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1389 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1390 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1391 | if (!isValid) { |
| 1392 | return; |
| 1393 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1394 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1395 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1396 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1397 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1398 | mApp.startActivity(intent); |
| 1399 | } finally { |
| 1400 | Binder.restoreCallingIdentity(identity); |
| 1401 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1404 | public boolean supplyPin(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1405 | return supplyPinForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1408 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1409 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1410 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1411 | } |
| 1412 | |
| 1413 | public boolean supplyPuk(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1414 | return supplyPukForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1417 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1418 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1419 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1420 | } |
| 1421 | |
| 1422 | /** {@hide} */ |
| 1423 | public int[] supplyPinReportResult(String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1424 | return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1427 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1428 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1429 | |
| 1430 | final long identity = Binder.clearCallingIdentity(); |
| 1431 | try { |
| 1432 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1433 | checkSimPin.start(); |
| 1434 | return checkSimPin.unlockSim(null, pin); |
| 1435 | } finally { |
| 1436 | Binder.restoreCallingIdentity(identity); |
| 1437 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1440 | /** {@hide} */ |
| 1441 | public int[] supplyPukReportResult(String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1442 | return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1445 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1446 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1447 | |
| 1448 | final long identity = Binder.clearCallingIdentity(); |
| 1449 | try { |
| 1450 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1451 | checkSimPuk.start(); |
| 1452 | return checkSimPuk.unlockSim(puk, pin); |
| 1453 | } finally { |
| 1454 | Binder.restoreCallingIdentity(identity); |
| 1455 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1459 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1460 | * a synchronous one. |
| 1461 | */ |
| 1462 | private static class UnlockSim extends Thread { |
| 1463 | |
| 1464 | private final IccCard mSimCard; |
| 1465 | |
| 1466 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1467 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1468 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1469 | |
| 1470 | // For replies from SimCard interface |
| 1471 | private Handler mHandler; |
| 1472 | |
| 1473 | // For async handler to identify request type |
| 1474 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1475 | |
| 1476 | public UnlockSim(IccCard simCard) { |
| 1477 | mSimCard = simCard; |
| 1478 | } |
| 1479 | |
| 1480 | @Override |
| 1481 | public void run() { |
| 1482 | Looper.prepare(); |
| 1483 | synchronized (UnlockSim.this) { |
| 1484 | mHandler = new Handler() { |
| 1485 | @Override |
| 1486 | public void handleMessage(Message msg) { |
| 1487 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1488 | switch (msg.what) { |
| 1489 | case SUPPLY_PIN_COMPLETE: |
| 1490 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1491 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1492 | mRetryCount = msg.arg1; |
| 1493 | if (ar.exception != null) { |
| 1494 | if (ar.exception instanceof CommandException && |
| 1495 | ((CommandException)(ar.exception)).getCommandError() |
| 1496 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1497 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1498 | } else { |
| 1499 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1500 | } |
| 1501 | } else { |
| 1502 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1504 | mDone = true; |
| 1505 | UnlockSim.this.notifyAll(); |
| 1506 | } |
| 1507 | break; |
| 1508 | } |
| 1509 | } |
| 1510 | }; |
| 1511 | UnlockSim.this.notifyAll(); |
| 1512 | } |
| 1513 | Looper.loop(); |
| 1514 | } |
| 1515 | |
| 1516 | /* |
| 1517 | * Use PIN or PUK to unlock SIM card |
| 1518 | * |
| 1519 | * If PUK is null, unlock SIM card with PIN |
| 1520 | * |
| 1521 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1522 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1523 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1524 | |
| 1525 | while (mHandler == null) { |
| 1526 | try { |
| 1527 | wait(); |
| 1528 | } catch (InterruptedException e) { |
| 1529 | Thread.currentThread().interrupt(); |
| 1530 | } |
| 1531 | } |
| 1532 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1533 | |
| 1534 | if (puk == null) { |
| 1535 | mSimCard.supplyPin(pin, callback); |
| 1536 | } else { |
| 1537 | mSimCard.supplyPuk(puk, pin, callback); |
| 1538 | } |
| 1539 | |
| 1540 | while (!mDone) { |
| 1541 | try { |
| 1542 | Log.d(LOG_TAG, "wait for done"); |
| 1543 | wait(); |
| 1544 | } catch (InterruptedException e) { |
| 1545 | // Restore the interrupted status |
| 1546 | Thread.currentThread().interrupt(); |
| 1547 | } |
| 1548 | } |
| 1549 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1550 | int[] resultArray = new int[2]; |
| 1551 | resultArray[0] = mResult; |
| 1552 | resultArray[1] = mRetryCount; |
| 1553 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1558 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1559 | |
| 1560 | } |
| 1561 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1562 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1563 | // No permission check needed here: this call is harmless, and it's |
| 1564 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1565 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1566 | final long identity = Binder.clearCallingIdentity(); |
| 1567 | try { |
| 1568 | final Phone phone = getPhone(subId); |
| 1569 | if (phone != null) { |
| 1570 | phone.updateServiceLocation(); |
| 1571 | } |
| 1572 | } finally { |
| 1573 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1574 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1577 | @Override |
| 1578 | public boolean isRadioOn(String callingPackage) { |
| 1579 | return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1582 | @Override |
| 1583 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1584 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 1585 | mApp, subId, callingPackage, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1586 | return false; |
| 1587 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1588 | |
| 1589 | final long identity = Binder.clearCallingIdentity(); |
| 1590 | try { |
| 1591 | return isRadioOnForSubscriber(subId); |
| 1592 | } finally { |
| 1593 | Binder.restoreCallingIdentity(identity); |
| 1594 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1598 | final long identity = Binder.clearCallingIdentity(); |
| 1599 | try { |
| 1600 | final Phone phone = getPhone(subId); |
| 1601 | if (phone != null) { |
| 1602 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1603 | } else { |
| 1604 | return false; |
| 1605 | } |
| 1606 | } finally { |
| 1607 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1608 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1612 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1613 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1614 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1615 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1616 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1617 | |
| 1618 | final long identity = Binder.clearCallingIdentity(); |
| 1619 | try { |
| 1620 | final Phone phone = getPhone(subId); |
| 1621 | if (phone != null) { |
| 1622 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1623 | } |
| 1624 | } finally { |
| 1625 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1626 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1630 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1633 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1634 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1635 | |
| 1636 | final long identity = Binder.clearCallingIdentity(); |
| 1637 | try { |
| 1638 | final Phone phone = getPhone(subId); |
| 1639 | if (phone == null) { |
| 1640 | return false; |
| 1641 | } |
| 1642 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1643 | toggleRadioOnOffForSubscriber(subId); |
| 1644 | } |
| 1645 | return true; |
| 1646 | } finally { |
| 1647 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1648 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1649 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1650 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1651 | public boolean needMobileRadioShutdown() { |
| 1652 | /* |
| 1653 | * If any of the Radios are available, it will need to be |
| 1654 | * shutdown. So return true if any Radio is available. |
| 1655 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1656 | final long identity = Binder.clearCallingIdentity(); |
| 1657 | try { |
| 1658 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1659 | Phone phone = PhoneFactory.getPhone(i); |
| 1660 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1661 | } |
| 1662 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1663 | return false; |
| 1664 | } finally { |
| 1665 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1666 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1669 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1670 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1671 | enforceModifyPermission(); |
| 1672 | |
| 1673 | final long identity = Binder.clearCallingIdentity(); |
| 1674 | try { |
| 1675 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1676 | logv("Shutting down Phone " + i); |
| 1677 | shutdownRadioUsingPhoneId(i); |
| 1678 | } |
| 1679 | } finally { |
| 1680 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1685 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1686 | if (phone != null && phone.isRadioAvailable()) { |
| 1687 | phone.shutdownRadio(); |
| 1688 | } |
| 1689 | } |
| 1690 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1692 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1693 | |
| 1694 | final long identity = Binder.clearCallingIdentity(); |
| 1695 | try { |
| 1696 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1697 | if (defaultPhone != null) { |
| 1698 | defaultPhone.setRadioPower(turnOn); |
| 1699 | return true; |
| 1700 | } else { |
| 1701 | loge("There's no default phone."); |
| 1702 | return false; |
| 1703 | } |
| 1704 | } finally { |
| 1705 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1706 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1709 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1710 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1711 | |
| 1712 | final long identity = Binder.clearCallingIdentity(); |
| 1713 | try { |
| 1714 | final Phone phone = getPhone(subId); |
| 1715 | if (phone != null) { |
| 1716 | phone.setRadioPower(turnOn); |
| 1717 | return true; |
| 1718 | } else { |
| 1719 | return false; |
| 1720 | } |
| 1721 | } finally { |
| 1722 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1726 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1727 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1728 | public boolean enableDataConnectivity() { |
| 1729 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1730 | |
| 1731 | final long identity = Binder.clearCallingIdentity(); |
| 1732 | try { |
| 1733 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1734 | final Phone phone = getPhone(subId); |
| 1735 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1736 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1737 | return true; |
| 1738 | } else { |
| 1739 | return false; |
| 1740 | } |
| 1741 | } finally { |
| 1742 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1743 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1746 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1747 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1748 | public boolean disableDataConnectivity() { |
| 1749 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1750 | |
| 1751 | final long identity = Binder.clearCallingIdentity(); |
| 1752 | try { |
| 1753 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1754 | final Phone phone = getPhone(subId); |
| 1755 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1756 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1757 | return true; |
| 1758 | } else { |
| 1759 | return false; |
| 1760 | } |
| 1761 | } finally { |
| 1762 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1763 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1764 | } |
| 1765 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1766 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1767 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1768 | final long identity = Binder.clearCallingIdentity(); |
| 1769 | try { |
| 1770 | final Phone phone = getPhone(subId); |
| 1771 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1772 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1773 | } else { |
| 1774 | return false; |
| 1775 | } |
| 1776 | } finally { |
| 1777 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1778 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1782 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1785 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1786 | enforceCallPermission(); |
| 1787 | |
| 1788 | final long identity = Binder.clearCallingIdentity(); |
| 1789 | try { |
| 1790 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1791 | return; |
| 1792 | } |
| 1793 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1794 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1795 | } finally { |
| 1796 | Binder.restoreCallingIdentity(identity); |
| 1797 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1798 | }; |
| 1799 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1800 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1801 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1802 | |
| 1803 | final long identity = Binder.clearCallingIdentity(); |
| 1804 | try { |
| 1805 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1806 | return false; |
| 1807 | } |
| 1808 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1809 | } finally { |
| 1810 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1811 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1814 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1815 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1818 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1819 | final long identity = Binder.clearCallingIdentity(); |
| 1820 | try { |
| 1821 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1822 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1823 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1824 | } finally { |
| 1825 | Binder.restoreCallingIdentity(identity); |
| 1826 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1829 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1830 | public int getDataState() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1831 | final long identity = Binder.clearCallingIdentity(); |
| 1832 | try { |
| 1833 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1834 | if (phone != null) { |
| 1835 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1836 | } else { |
| 1837 | return PhoneConstantConversions.convertDataState( |
| 1838 | PhoneConstants.DataState.DISCONNECTED); |
| 1839 | } |
| 1840 | } finally { |
| 1841 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1842 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1845 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1846 | public int getDataActivity() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1847 | final long identity = Binder.clearCallingIdentity(); |
| 1848 | try { |
| 1849 | Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId()); |
| 1850 | if (phone != null) { |
| 1851 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1852 | } else { |
| 1853 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1854 | } |
| 1855 | } finally { |
| 1856 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1857 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1861 | public Bundle getCellLocation(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1862 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 1863 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 1864 | |
| 1865 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1866 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1867 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1868 | .setCallingPackage(callingPackage) |
| 1869 | .setCallingPid(Binder.getCallingPid()) |
| 1870 | .setCallingUid(Binder.getCallingUid()) |
| 1871 | .setMethod("getCellLocation") |
| 1872 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1873 | .build()); |
| 1874 | switch (locationResult) { |
| 1875 | case DENIED_HARD: |
| 1876 | throw new SecurityException("Not allowed to access cell location"); |
| 1877 | case DENIED_SOFT: |
| 1878 | return new Bundle(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | } |
| 1880 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 1881 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1882 | final long identity = Binder.clearCallingIdentity(); |
| 1883 | try { |
| 1884 | if (DBG_LOC) log("getCellLocation: is active user"); |
| 1885 | Bundle data = new Bundle(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1886 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1887 | CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
| 1888 | cl.fillInNotifierBundle(data); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1889 | return data; |
| 1890 | } finally { |
| 1891 | Binder.restoreCallingIdentity(identity); |
| 1892 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1895 | @Override |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1896 | public String getNetworkCountryIsoForPhone(int phoneId) { |
| 1897 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 1898 | // registered cell info, so return a NULL country instead. |
| 1899 | final long identity = Binder.clearCallingIdentity(); |
| 1900 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 1901 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 1902 | // Get default phone in this case. |
| 1903 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 1904 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1905 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 1906 | // Todo: fix this when we can get the actual cellular network info when the device |
| 1907 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1908 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
| 1909 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) { |
| 1910 | return ""; |
| 1911 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1912 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1913 | if (phone != null) { |
| 1914 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 1915 | if (sst != null) { |
| 1916 | LocaleTracker lt = sst.getLocaleTracker(); |
| 1917 | if (lt != null) { |
| 1918 | return lt.getCurrentCountry(); |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1923 | } finally { |
| 1924 | Binder.restoreCallingIdentity(identity); |
| 1925 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1929 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1930 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1933 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1934 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1935 | mApp.enforceCallingOrSelfPermission( |
| 1936 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1937 | |
| 1938 | final long identity = Binder.clearCallingIdentity(); |
| 1939 | try { |
| 1940 | final Phone phone = getPhone(subId); |
| 1941 | if (phone != null) { |
| 1942 | phone.enableLocationUpdates(); |
| 1943 | } |
| 1944 | } finally { |
| 1945 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1946 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | @Override |
| 1950 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1951 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1954 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1955 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1956 | mApp.enforceCallingOrSelfPermission( |
| 1957 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1958 | |
| 1959 | final long identity = Binder.clearCallingIdentity(); |
| 1960 | try { |
| 1961 | final Phone phone = getPhone(subId); |
| 1962 | if (phone != null) { |
| 1963 | phone.disableLocationUpdates(); |
| 1964 | } |
| 1965 | } finally { |
| 1966 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1967 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1970 | /** |
| 1971 | * Returns the target SDK version number for a given package name. |
| 1972 | * |
| 1973 | * @return target SDK if the package is found or INT_MAX. |
| 1974 | */ |
| 1975 | private int getTargetSdk(String packageName) { |
| 1976 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1977 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo( |
| 1978 | packageName, 0); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1979 | if (ai != null) return ai.targetSdkVersion; |
| 1980 | } catch (PackageManager.NameNotFoundException unexpected) { |
| 1981 | } |
| 1982 | return Integer.MAX_VALUE; |
| 1983 | } |
| 1984 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1985 | @Override |
| 1986 | @SuppressWarnings("unchecked") |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 1987 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) { |
| 1988 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 1989 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 1990 | throw new SecurityException( |
| 1991 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 1992 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 1993 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1994 | if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(), |
| 1995 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 1996 | return null; |
| 1997 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 1998 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 1999 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2001 | List<CellInfo> info = getAllCellInfo(callingPackage); |
| 2002 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2003 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2004 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2005 | for (CellInfo ci : info) { |
| 2006 | if (ci instanceof CellInfoGsm) { |
| 2007 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2008 | } else if (ci instanceof CellInfoWcdma) { |
| 2009 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2010 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2011 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2012 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2015 | private List<CellInfo> getCachedCellInfo() { |
| 2016 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2017 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2018 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2019 | if (info != null) cellInfos.addAll(info); |
| 2020 | } |
| 2021 | return cellInfos; |
| 2022 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2023 | |
| 2024 | @Override |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2025 | public List<CellInfo> getAllCellInfo(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2026 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2027 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2028 | |
| 2029 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2030 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2031 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2032 | .setCallingPackage(callingPackage) |
| 2033 | .setCallingPid(Binder.getCallingPid()) |
| 2034 | .setCallingUid(Binder.getCallingUid()) |
| 2035 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2036 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2037 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2038 | .build()); |
| 2039 | switch (locationResult) { |
| 2040 | case DENIED_HARD: |
| 2041 | throw new SecurityException("Not allowed to access cell info"); |
| 2042 | case DENIED_SOFT: |
| 2043 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2046 | final int targetSdk = getTargetSdk(callingPackage); |
| 2047 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2048 | return getCachedCellInfo(); |
| 2049 | } |
| 2050 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2051 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2052 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2053 | final long identity = Binder.clearCallingIdentity(); |
| 2054 | try { |
| 2055 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2056 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2057 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2058 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2059 | if (info != null) cellInfos.addAll(info); |
| 2060 | } |
| 2061 | return cellInfos; |
| 2062 | } finally { |
| 2063 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | } |
| 2065 | } |
| 2066 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2067 | @Override |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2068 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) { |
| 2069 | requestCellInfoUpdateInternal( |
| 2070 | subId, cb, callingPackage, getWorkSource(Binder.getCallingUid())); |
| 2071 | } |
| 2072 | |
| 2073 | @Override |
| 2074 | public void requestCellInfoUpdateWithWorkSource( |
| 2075 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
| 2076 | enforceModifyPermission(); |
| 2077 | requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource); |
| 2078 | } |
| 2079 | |
| 2080 | private void requestCellInfoUpdateInternal( |
| 2081 | int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2082 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2083 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2084 | |
| 2085 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2086 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2087 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2088 | .setCallingPackage(callingPackage) |
| 2089 | .setCallingPid(Binder.getCallingPid()) |
| 2090 | .setCallingUid(Binder.getCallingUid()) |
| 2091 | .setMethod("requestCellInfoUpdate") |
| 2092 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2093 | .build()); |
| 2094 | switch (locationResult) { |
| 2095 | case DENIED_HARD: |
| 2096 | throw new SecurityException("Not allowed to access cell info"); |
| 2097 | case DENIED_SOFT: |
| 2098 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | final Phone phone = getPhone(subId); |
| 2102 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2103 | |
| 2104 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2105 | } |
| 2106 | |
| 2107 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2109 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2110 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2111 | |
| 2112 | final long identity = Binder.clearCallingIdentity(); |
| 2113 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2114 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2115 | } finally { |
| 2116 | Binder.restoreCallingIdentity(identity); |
| 2117 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 | } |
| 2119 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2120 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2121 | public String getImeiForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2122 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2123 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2124 | return null; |
| 2125 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2126 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2127 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2128 | callingPackage, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2129 | return null; |
| 2130 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2131 | |
| 2132 | final long identity = Binder.clearCallingIdentity(); |
| 2133 | try { |
| 2134 | return phone.getImei(); |
| 2135 | } finally { |
| 2136 | Binder.restoreCallingIdentity(identity); |
| 2137 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2141 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2142 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2143 | String tac = null; |
| 2144 | if (phone != null) { |
| 2145 | String imei = phone.getImei(); |
| 2146 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2147 | } |
| 2148 | return tac; |
| 2149 | } |
| 2150 | |
| 2151 | @Override |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2152 | public String getMeidForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2153 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2154 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2155 | return null; |
| 2156 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2157 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2158 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2159 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 2160 | callingPackage, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2161 | return null; |
| 2162 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2163 | |
| 2164 | final long identity = Binder.clearCallingIdentity(); |
| 2165 | try { |
| 2166 | return phone.getMeid(); |
| 2167 | } finally { |
| 2168 | Binder.restoreCallingIdentity(identity); |
| 2169 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2173 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2174 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2175 | String manufacturerCode = null; |
| 2176 | if (phone != null) { |
| 2177 | String meid = phone.getMeid(); |
| 2178 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2179 | } |
| 2180 | return manufacturerCode; |
| 2181 | } |
| 2182 | |
| 2183 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2184 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2185 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2186 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2187 | return null; |
| 2188 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2189 | int subId = phone.getSubId(); |
| 2190 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2191 | mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) { |
| 2192 | return null; |
| 2193 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2194 | |
| 2195 | final long identity = Binder.clearCallingIdentity(); |
| 2196 | try { |
| 2197 | return phone.getDeviceSvn(); |
| 2198 | } finally { |
| 2199 | Binder.restoreCallingIdentity(identity); |
| 2200 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2203 | @Override |
| 2204 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2205 | final long identity = Binder.clearCallingIdentity(); |
| 2206 | try { |
| 2207 | final Phone phone = getPhone(subId); |
| 2208 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2209 | } finally { |
| 2210 | Binder.restoreCallingIdentity(identity); |
| 2211 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | @Override |
| 2215 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2216 | final long identity = Binder.clearCallingIdentity(); |
| 2217 | try { |
| 2218 | final Phone phone = getPhone(subId); |
| 2219 | return phone == null ? null : phone.getCarrierName(); |
| 2220 | } finally { |
| 2221 | Binder.restoreCallingIdentity(identity); |
| 2222 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2223 | } |
| 2224 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2225 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2226 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2227 | final long identity = Binder.clearCallingIdentity(); |
| 2228 | try { |
| 2229 | final Phone phone = getPhone(subId); |
| 2230 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2231 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2232 | } finally { |
| 2233 | Binder.restoreCallingIdentity(identity); |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2238 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2239 | final long identity = Binder.clearCallingIdentity(); |
| 2240 | try { |
| 2241 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2242 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2243 | } finally { |
| 2244 | Binder.restoreCallingIdentity(identity); |
| 2245 | } |
| 2246 | } |
| 2247 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2248 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2249 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2250 | if (!isSubscriptionMccMnc) { |
| 2251 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2252 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2253 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2254 | if (phone == null) { |
| 2255 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2256 | } |
| 2257 | final long identity = Binder.clearCallingIdentity(); |
| 2258 | try { |
| 2259 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2260 | } finally { |
| 2261 | Binder.restoreCallingIdentity(identity); |
| 2262 | } |
| 2263 | } |
| 2264 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2265 | // |
| 2266 | // Internal helper methods. |
| 2267 | // |
| 2268 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2269 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2270 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2271 | * |
| 2272 | * @throws SecurityException if the caller does not have the required permission |
| 2273 | */ |
| 2274 | private void enforceModifyPermission() { |
| 2275 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2276 | } |
| 2277 | |
| 2278 | /** |
| 2279 | * Make sure the caller has the CALL_PHONE permission. |
| 2280 | * |
| 2281 | * @throws SecurityException if the caller does not have the required permission |
| 2282 | */ |
| 2283 | private void enforceCallPermission() { |
| 2284 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2285 | } |
| 2286 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2287 | private void enforceConnectivityInternalPermission() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2288 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2289 | "ConnectivityService"); |
| 2290 | } |
| 2291 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2292 | private String createTelUrl(String number) { |
| 2293 | if (TextUtils.isEmpty(number)) { |
| 2294 | return null; |
| 2295 | } |
| 2296 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2297 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2300 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2302 | } |
| 2303 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2304 | private static void logv(String msg) { |
| 2305 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2306 | } |
| 2307 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2308 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2309 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2310 | } |
| 2311 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2312 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2314 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2317 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2318 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2319 | final long identity = Binder.clearCallingIdentity(); |
| 2320 | try { |
| 2321 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2322 | if (phone == null) { |
| 2323 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2324 | } else { |
| 2325 | return phone.getPhoneType(); |
| 2326 | } |
| 2327 | } finally { |
| 2328 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2329 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | /** |
| 2333 | * Returns the CDMA ERI icon index to display |
| 2334 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2335 | @Override |
| 2336 | public int getCdmaEriIconIndex(String callingPackage) { |
| 2337 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2340 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2341 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2342 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2343 | mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2344 | return -1; |
| 2345 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2346 | |
| 2347 | final long identity = Binder.clearCallingIdentity(); |
| 2348 | try { |
| 2349 | final Phone phone = getPhone(subId); |
| 2350 | if (phone != null) { |
| 2351 | return phone.getCdmaEriIconIndex(); |
| 2352 | } else { |
| 2353 | return -1; |
| 2354 | } |
| 2355 | } finally { |
| 2356 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2357 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | /** |
| 2361 | * Returns the CDMA ERI icon mode, |
| 2362 | * 0 - ON |
| 2363 | * 1 - FLASHING |
| 2364 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2365 | @Override |
| 2366 | public int getCdmaEriIconMode(String callingPackage) { |
| 2367 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2370 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2371 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2372 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2373 | mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2374 | return -1; |
| 2375 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2376 | |
| 2377 | final long identity = Binder.clearCallingIdentity(); |
| 2378 | try { |
| 2379 | final Phone phone = getPhone(subId); |
| 2380 | if (phone != null) { |
| 2381 | return phone.getCdmaEriIconMode(); |
| 2382 | } else { |
| 2383 | return -1; |
| 2384 | } |
| 2385 | } finally { |
| 2386 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2387 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | /** |
| 2391 | * Returns the CDMA ERI text, |
| 2392 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2393 | @Override |
| 2394 | public String getCdmaEriText(String callingPackage) { |
| 2395 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2398 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2399 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2400 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2401 | mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2402 | return null; |
| 2403 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2404 | |
| 2405 | final long identity = Binder.clearCallingIdentity(); |
| 2406 | try { |
| 2407 | final Phone phone = getPhone(subId); |
| 2408 | if (phone != null) { |
| 2409 | return phone.getCdmaEriText(); |
| 2410 | } else { |
| 2411 | return null; |
| 2412 | } |
| 2413 | } finally { |
| 2414 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2415 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2419 | * Returns the CDMA MDN. |
| 2420 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2421 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2422 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2423 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2424 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2425 | |
| 2426 | final long identity = Binder.clearCallingIdentity(); |
| 2427 | try { |
| 2428 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2429 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2430 | return phone.getLine1Number(); |
| 2431 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2432 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2433 | return null; |
| 2434 | } |
| 2435 | } finally { |
| 2436 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | * Returns the CDMA MIN. |
| 2442 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2443 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2444 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2445 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2446 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2447 | |
| 2448 | final long identity = Binder.clearCallingIdentity(); |
| 2449 | try { |
| 2450 | final Phone phone = getPhone(subId); |
| 2451 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2452 | return phone.getCdmaMin(); |
| 2453 | } else { |
| 2454 | return null; |
| 2455 | } |
| 2456 | } finally { |
| 2457 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2458 | } |
| 2459 | } |
| 2460 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2461 | @Override |
| 2462 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2463 | INumberVerificationCallback callback, String callingPackage) { |
| 2464 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2465 | != PERMISSION_GRANTED) { |
| 2466 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2467 | } |
| 2468 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2469 | |
| 2470 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2471 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2472 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2473 | } |
| 2474 | |
| 2475 | if (range == null) { |
| 2476 | throw new NullPointerException("Range must be non-null"); |
| 2477 | } |
| 2478 | |
| 2479 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2480 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2481 | |
| 2482 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2483 | } |
| 2484 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2485 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | * Returns true if CDMA provisioning needs to run. |
| 2487 | */ |
| 2488 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2489 | final long identity = Binder.clearCallingIdentity(); |
| 2490 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2491 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2492 | } finally { |
| 2493 | Binder.restoreCallingIdentity(identity); |
| 2494 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2498 | * Sets the voice mail number of a given subId. |
| 2499 | */ |
| 2500 | @Override |
| 2501 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2502 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2503 | |
| 2504 | final long identity = Binder.clearCallingIdentity(); |
| 2505 | try { |
| 2506 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2507 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2508 | return success; |
| 2509 | } finally { |
| 2510 | Binder.restoreCallingIdentity(identity); |
| 2511 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2512 | } |
| 2513 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2514 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2515 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2516 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2517 | String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2518 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2519 | throw new SecurityException("caller must be system dialer"); |
| 2520 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2521 | |
| 2522 | final long identity = Binder.clearCallingIdentity(); |
| 2523 | try { |
| 2524 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2525 | if (phoneAccountHandle == null) { |
| 2526 | return null; |
| 2527 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2528 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | } finally { |
| 2530 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2531 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | @Override |
Ta-wei Yen | 409ac56 | 2017-03-06 16:00:44 -0800 | [diff] [blame] | 2535 | public String getVisualVoicemailPackageName(String callingPackage, int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2536 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2537 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2538 | mApp, subId, callingPackage, "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2539 | return null; |
| 2540 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2541 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2542 | final long identity = Binder.clearCallingIdentity(); |
| 2543 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2544 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2545 | } finally { |
| 2546 | Binder.restoreCallingIdentity(identity); |
| 2547 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2551 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2552 | VisualVoicemailSmsFilterSettings settings) { |
| 2553 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2554 | |
| 2555 | final long identity = Binder.clearCallingIdentity(); |
| 2556 | try { |
| 2557 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2558 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | } finally { |
| 2560 | Binder.restoreCallingIdentity(identity); |
| 2561 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2565 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2566 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2567 | |
| 2568 | final long identity = Binder.clearCallingIdentity(); |
| 2569 | try { |
| 2570 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2571 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2572 | } finally { |
| 2573 | Binder.restoreCallingIdentity(identity); |
| 2574 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2578 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2579 | String callingPackage, int subId) { |
| 2580 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2581 | |
| 2582 | final long identity = Binder.clearCallingIdentity(); |
| 2583 | try { |
| 2584 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2585 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2586 | } finally { |
| 2587 | Binder.restoreCallingIdentity(identity); |
| 2588 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2592 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2593 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2594 | |
| 2595 | final long identity = Binder.clearCallingIdentity(); |
| 2596 | try { |
| 2597 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2598 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2599 | } finally { |
| 2600 | Binder.restoreCallingIdentity(identity); |
| 2601 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | @Override |
| 2605 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2606 | String number, int port, String text, PendingIntent sentIntent) { |
| 2607 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2608 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2609 | enforceSendSmsPermission(); |
| 2610 | // Make the calls as the phone process. |
| 2611 | final long identity = Binder.clearCallingIdentity(); |
| 2612 | try { |
| 2613 | SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId); |
| 2614 | if (port == 0) { |
| 2615 | smsManager.sendTextMessageWithSelfPermissions(number, null, text, |
| 2616 | sentIntent, null, false); |
| 2617 | } else { |
| 2618 | byte[] data = text.getBytes(StandardCharsets.UTF_8); |
| 2619 | smsManager.sendDataMessageWithSelfPermissions(number, null, |
| 2620 | (short) port, data, sentIntent, null); |
| 2621 | } |
| 2622 | } finally { |
| 2623 | Binder.restoreCallingIdentity(identity); |
| 2624 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2625 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2626 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2627 | * Sets the voice activation state of a given subId. |
| 2628 | */ |
| 2629 | @Override |
| 2630 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2632 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2633 | |
| 2634 | final long identity = Binder.clearCallingIdentity(); |
| 2635 | try { |
| 2636 | final Phone phone = getPhone(subId); |
| 2637 | if (phone != null) { |
| 2638 | phone.setVoiceActivationState(activationState); |
| 2639 | } else { |
| 2640 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2641 | } |
| 2642 | } finally { |
| 2643 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | /** |
| 2648 | * Sets the data activation state of a given subId. |
| 2649 | */ |
| 2650 | @Override |
| 2651 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2652 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2653 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | |
| 2655 | final long identity = Binder.clearCallingIdentity(); |
| 2656 | try { |
| 2657 | final Phone phone = getPhone(subId); |
| 2658 | if (phone != null) { |
| 2659 | phone.setDataActivationState(activationState); |
| 2660 | } else { |
| 2661 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2662 | } |
| 2663 | } finally { |
| 2664 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2665 | } |
| 2666 | } |
| 2667 | |
| 2668 | /** |
| 2669 | * Returns the voice activation state of a given subId. |
| 2670 | */ |
| 2671 | @Override |
| 2672 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2673 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2674 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2675 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | final long identity = Binder.clearCallingIdentity(); |
| 2677 | try { |
| 2678 | if (phone != null) { |
| 2679 | return phone.getVoiceActivationState(); |
| 2680 | } else { |
| 2681 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2682 | } |
| 2683 | } finally { |
| 2684 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | /** |
| 2689 | * Returns the data activation state of a given subId. |
| 2690 | */ |
| 2691 | @Override |
| 2692 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2693 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2694 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2695 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2696 | final long identity = Binder.clearCallingIdentity(); |
| 2697 | try { |
| 2698 | if (phone != null) { |
| 2699 | return phone.getDataActivationState(); |
| 2700 | } else { |
| 2701 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2702 | } |
| 2703 | } finally { |
| 2704 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2709 | * Returns the unread count of voicemails for a subId |
| 2710 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2711 | @Override |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2712 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) { |
| 2713 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2714 | mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) { |
| 2715 | return 0; |
| 2716 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2717 | final long identity = Binder.clearCallingIdentity(); |
| 2718 | try { |
| 2719 | final Phone phone = getPhone(subId); |
| 2720 | if (phone != null) { |
| 2721 | return phone.getVoiceMessageCount(); |
| 2722 | } else { |
| 2723 | return 0; |
| 2724 | } |
| 2725 | } finally { |
| 2726 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2727 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2731 | * returns true, if the device is in a state where both voice and data |
| 2732 | * are supported simultaneously. This can change based on location or network condition. |
| 2733 | */ |
| 2734 | @Override |
| 2735 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2736 | final long identity = Binder.clearCallingIdentity(); |
| 2737 | try { |
| 2738 | final Phone phone = getPhone(subId); |
| 2739 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2740 | } finally { |
| 2741 | Binder.restoreCallingIdentity(identity); |
| 2742 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2746 | * Send the dialer code if called from the current default dialer or the caller has |
| 2747 | * carrier privilege. |
| 2748 | * @param inputCode The dialer code to send |
| 2749 | */ |
| 2750 | @Override |
| 2751 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2752 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2753 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2754 | String defaultDialer = TelecomManager.from(defaultPhone.getContext()) |
| 2755 | .getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2756 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2757 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2758 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2759 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | |
| 2761 | final long identity = Binder.clearCallingIdentity(); |
| 2762 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2763 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2764 | } finally { |
| 2765 | Binder.restoreCallingIdentity(identity); |
| 2766 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | /** |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2770 | * Returns the data network type. |
| 2771 | * Legacy call, permission-free. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2772 | * |
| 2773 | * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}. |
| 2774 | */ |
| 2775 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2776 | public int getNetworkType() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2777 | final long identity = Binder.clearCallingIdentity(); |
| 2778 | try { |
| 2779 | final Phone phone = getPhone(getDefaultSubscription()); |
| 2780 | if (phone != null) { |
| 2781 | return phone.getServiceState().getDataNetworkType(); |
| 2782 | } else { |
| 2783 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 2784 | } |
| 2785 | } finally { |
| 2786 | Binder.restoreCallingIdentity(identity); |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 2787 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2790 | @Override |
| 2791 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2792 | if (!isActiveSubscription(subId)) { |
| 2793 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2794 | } |
| 2795 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2796 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2797 | } |
| 2798 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2799 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2800 | public boolean isInEmergencySmsMode() { |
| 2801 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2802 | final long identity = Binder.clearCallingIdentity(); |
| 2803 | try { |
| 2804 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2805 | if (phone.isInEmergencySmsMode()) { |
| 2806 | return true; |
| 2807 | } |
| 2808 | } |
| 2809 | } finally { |
| 2810 | Binder.restoreCallingIdentity(identity); |
| 2811 | } |
| 2812 | return false; |
| 2813 | } |
| 2814 | |
| 2815 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2816 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2817 | throws RemoteException { |
| 2818 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2819 | final long token = Binder.clearCallingIdentity(); |
| 2820 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2821 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2822 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2823 | .addRegistrationCallbackForSubscription(c, subId); |
| 2824 | } finally { |
| 2825 | Binder.restoreCallingIdentity(token); |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2830 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2831 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2832 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2833 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2834 | } |
| 2835 | Binder.withCleanCallingIdentity(() -> { |
| 2836 | try { |
| 2837 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2838 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2839 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2840 | } catch (IllegalArgumentException e) { |
| 2841 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2842 | + "is inactive, ignoring unregister."); |
| 2843 | // If the subscription is no longer active, just return, since the callback |
| 2844 | // will already have been removed internally. |
| 2845 | } |
| 2846 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2850 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2851 | throws RemoteException { |
| 2852 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2853 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2854 | final long token = Binder.clearCallingIdentity(); |
| 2855 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2856 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2857 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2858 | } finally { |
| 2859 | Binder.restoreCallingIdentity(token); |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2864 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2865 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2866 | |
| 2867 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2868 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2869 | } |
| 2870 | Binder.withCleanCallingIdentity(() -> { |
| 2871 | try { |
| 2872 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2873 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2874 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2875 | } catch (IllegalArgumentException e) { |
| 2876 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2877 | + "is inactive, ignoring unregister."); |
| 2878 | // If the subscription is no longer active, just return, since the callback |
| 2879 | // will already have been removed internally. |
| 2880 | } |
| 2881 | }); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2885 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2886 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2887 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2888 | final long token = Binder.clearCallingIdentity(); |
| 2889 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2890 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2891 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2892 | } catch (ImsException e) { |
| 2893 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2894 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2895 | } catch (IllegalArgumentException e) { |
| 2896 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2897 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2898 | } finally { |
| 2899 | Binder.restoreCallingIdentity(token); |
| 2900 | } |
| 2901 | } |
| 2902 | |
| 2903 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2904 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2905 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2906 | final long token = Binder.clearCallingIdentity(); |
| 2907 | try { |
| 2908 | Phone phone = getPhone(subId); |
| 2909 | if (phone == null) return false; |
| 2910 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(token); |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | @Override |
| 2917 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2918 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2919 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2920 | final long token = Binder.clearCallingIdentity(); |
| 2921 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2922 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2923 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(token); |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2930 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2932 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2933 | final long identity = Binder.clearCallingIdentity(); |
| 2934 | try { |
| 2935 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2936 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2937 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2938 | } finally { |
| 2939 | Binder.restoreCallingIdentity(identity); |
| 2940 | } |
| 2941 | } |
| 2942 | |
| 2943 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2944 | public boolean isVtSettingEnabled(int subId) { |
| 2945 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2946 | final long identity = Binder.clearCallingIdentity(); |
| 2947 | try { |
| 2948 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2949 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2950 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2957 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2959 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2960 | final long identity = Binder.clearCallingIdentity(); |
| 2961 | try { |
| 2962 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2963 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2964 | } finally { |
| 2965 | Binder.restoreCallingIdentity(identity); |
| 2966 | } |
| 2967 | } |
| 2968 | |
| 2969 | @Override |
| 2970 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2971 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2975 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2976 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2977 | } finally { |
| 2978 | Binder.restoreCallingIdentity(identity); |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2983 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2985 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2986 | final long identity = Binder.clearCallingIdentity(); |
| 2987 | try { |
| 2988 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2989 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(identity); |
| 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | @Override |
| 2996 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2997 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2998 | final long identity = Binder.clearCallingIdentity(); |
| 2999 | try { |
| 3000 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3001 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3002 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 3003 | } finally { |
| 3004 | Binder.restoreCallingIdentity(identity); |
| 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3009 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3010 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3011 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3012 | final long identity = Binder.clearCallingIdentity(); |
| 3013 | try { |
| 3014 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3015 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3016 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(identity); |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | @Override |
| 3023 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3025 | "setVoWiFiNonPersistent"); |
| 3026 | final long identity = Binder.clearCallingIdentity(); |
| 3027 | try { |
| 3028 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3029 | boolean isRoaming = TelephonyManager.from( |
| 3030 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3031 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3032 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3033 | } finally { |
| 3034 | Binder.restoreCallingIdentity(identity); |
| 3035 | } |
| 3036 | } |
| 3037 | |
| 3038 | @Override |
| 3039 | public int getVoWiFiModeSetting(int subId) { |
| 3040 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3041 | final long identity = Binder.clearCallingIdentity(); |
| 3042 | try { |
| 3043 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3044 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3045 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3046 | } finally { |
| 3047 | Binder.restoreCallingIdentity(identity); |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | @Override |
| 3052 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3053 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3054 | "setVoWiFiModeSetting"); |
| 3055 | final long identity = Binder.clearCallingIdentity(); |
| 3056 | try { |
| 3057 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3058 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3059 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3060 | } finally { |
| 3061 | Binder.restoreCallingIdentity(identity); |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | @Override |
| 3066 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3067 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3068 | final long identity = Binder.clearCallingIdentity(); |
| 3069 | try { |
| 3070 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3071 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3072 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3073 | } finally { |
| 3074 | Binder.restoreCallingIdentity(identity); |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | @Override |
| 3079 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3081 | "setVoWiFiRoamingModeSetting"); |
| 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3085 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3086 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | @Override |
| 3093 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3095 | "setRttCapabilityEnabled"); |
| 3096 | final long identity = Binder.clearCallingIdentity(); |
| 3097 | try { |
| 3098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3099 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3100 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | @Override |
| 3107 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3108 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3109 | final long identity = Binder.clearCallingIdentity(); |
| 3110 | try { |
| 3111 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3112 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3113 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3114 | } finally { |
| 3115 | Binder.restoreCallingIdentity(identity); |
| 3116 | } |
| 3117 | } |
| 3118 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3119 | @Override |
| 3120 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3121 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 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, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3126 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3127 | } finally { |
| 3128 | Binder.restoreCallingIdentity(identity); |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | @Override |
| 3133 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3134 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3135 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3136 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3137 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3138 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3139 | try { |
| 3140 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3141 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3142 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3143 | } catch (IllegalArgumentException e) { |
| 3144 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3145 | + "is inactive, ignoring unregister."); |
| 3146 | // If the subscription is no longer active, just return, since the callback will already |
| 3147 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3148 | } finally { |
| 3149 | Binder.restoreCallingIdentity(identity); |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3154 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3155 | boolean isProvisioned) { |
| 3156 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3157 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3158 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3159 | } |
| 3160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3161 | "setProvisioningStatusForCapability"); |
| 3162 | final long identity = Binder.clearCallingIdentity(); |
| 3163 | try { |
| 3164 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3165 | Phone phone = getPhone(subId); |
| 3166 | if (phone == null) { |
| 3167 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3168 | + subId); |
| 3169 | return; |
| 3170 | } |
| 3171 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3172 | return; |
| 3173 | } |
| 3174 | |
| 3175 | // this capability requires provisioning, route to the correct API. |
| 3176 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3177 | switch (capability) { |
| 3178 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3179 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3180 | ims.setVolteProvisioned(isProvisioned); |
| 3181 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3182 | ims.setWfcProvisioned(isProvisioned); |
| 3183 | } |
| 3184 | break; |
| 3185 | } |
| 3186 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3187 | // There is currently no difference in VT provisioning type. |
| 3188 | ims.setVtProvisioned(isProvisioned); |
| 3189 | break; |
| 3190 | } |
| 3191 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3192 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3193 | // change the capability of the feature instead if needed. |
| 3194 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3195 | == isProvisioned) { |
| 3196 | // No change in provisioning. |
| 3197 | return; |
| 3198 | } |
| 3199 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3200 | try { |
| 3201 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3202 | } catch (ImsException e) { |
| 3203 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3204 | + ", Exception" + e.getMessage()); |
| 3205 | } |
| 3206 | break; |
| 3207 | } |
| 3208 | default: { |
| 3209 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3210 | + capability + "', which does not require provisioning."); |
| 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(identity); |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | @Override |
| 3220 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3221 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3222 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3223 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3224 | } |
| 3225 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3226 | final long identity = Binder.clearCallingIdentity(); |
| 3227 | try { |
| 3228 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3229 | Phone phone = getPhone(subId); |
| 3230 | if (phone == null) { |
| 3231 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3232 | + subId); |
| 3233 | // We will fail with "true" as the provisioning status because this is the default |
| 3234 | // if we do not require provisioning. |
| 3235 | return true; |
| 3236 | } |
| 3237 | |
| 3238 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3239 | return true; |
| 3240 | } |
| 3241 | |
| 3242 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3243 | switch (capability) { |
| 3244 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3245 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3246 | return ims.isVolteProvisionedOnDevice(); |
| 3247 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3248 | return ims.isWfcProvisionedOnDevice(); |
| 3249 | } |
| 3250 | // This should never happen, since we are checking tech above to make sure it |
| 3251 | // is either LTE or IWLAN. |
| 3252 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3253 | + "capability."); |
| 3254 | } |
| 3255 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3256 | // There is currently no difference in VT provisioning type. |
| 3257 | return ims.isVtProvisionedOnDevice(); |
| 3258 | } |
| 3259 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3260 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3261 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3262 | } |
| 3263 | default: { |
| 3264 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3265 | + capability + "', which does not require provisioning."); |
| 3266 | } |
| 3267 | } |
| 3268 | |
| 3269 | } finally { |
| 3270 | Binder.restoreCallingIdentity(identity); |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | @Override |
| 3275 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3276 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3277 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3278 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3279 | } |
| 3280 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3281 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3282 | return (provisionedBits & capability) > 0; |
| 3283 | } |
| 3284 | |
| 3285 | @Override |
| 3286 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3287 | boolean isProvisioned) { |
| 3288 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3289 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3290 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3291 | } |
| 3292 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3293 | "setProvisioningStatusForCapability"); |
| 3294 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3295 | // If the current provisioning status for capability already matches isProvisioned, |
| 3296 | // do nothing. |
| 3297 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3298 | return; |
| 3299 | } |
| 3300 | if (isProvisioned) { |
| 3301 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3302 | } else { |
| 3303 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | /** |
| 3308 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3309 | * technology. The bitfield should mirror the bitfield defined by |
| 3310 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3311 | */ |
| 3312 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3313 | String key = getMmTelProvisioningKey(subId, tech); |
| 3314 | // Default is no capabilities are provisioned. |
| 3315 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3316 | } |
| 3317 | |
| 3318 | /** |
| 3319 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3320 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3321 | * technology specified. |
| 3322 | * |
| 3323 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3324 | */ |
| 3325 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3326 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3327 | String key = getMmTelProvisioningKey(subId, tech); |
| 3328 | editor.putInt(key, newField); |
| 3329 | editor.commit(); |
| 3330 | } |
| 3331 | |
| 3332 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3333 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3334 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3335 | } |
| 3336 | |
| 3337 | /** |
| 3338 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3339 | * carrier associated with the subscription id. |
| 3340 | */ |
| 3341 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3342 | int capability) { |
| 3343 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3344 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3345 | boolean requireUtProvisioning = c.getBoolean( |
| 3346 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3347 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3348 | // the no-SIM case, where we would normally shortcut this to false. |
| 3349 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3350 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3351 | false); |
| 3352 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3353 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3354 | |
| 3355 | // First check to make sure that the capability requires provisioning. |
| 3356 | switch (capability) { |
| 3357 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3358 | // intentional fallthrough |
| 3359 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3360 | if (requireVoiceVtProvisioning) { |
| 3361 | // Voice and Video requires provisioning |
| 3362 | return true; |
| 3363 | } |
| 3364 | break; |
| 3365 | } |
| 3366 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3367 | if (requireUtProvisioning) { |
| 3368 | // UT requires provisioning |
| 3369 | return true; |
| 3370 | } |
| 3371 | break; |
| 3372 | } |
| 3373 | } |
| 3374 | return false; |
| 3375 | } |
| 3376 | |
| 3377 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3378 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3379 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3380 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3381 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3382 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3383 | final long identity = Binder.clearCallingIdentity(); |
| 3384 | try { |
| 3385 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3386 | int slotId = getSlotIndex(subId); |
| 3387 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3388 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3389 | + subId + "' for key:" + key); |
| 3390 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3391 | } |
| 3392 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3393 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3394 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3395 | + subId + "' for key:" + key); |
| 3396 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3397 | } finally { |
| 3398 | Binder.restoreCallingIdentity(identity); |
| 3399 | } |
| 3400 | } |
| 3401 | |
| 3402 | @Override |
| 3403 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3404 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3405 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3406 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3407 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3411 | int slotId = getSlotIndex(subId); |
| 3412 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3413 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3414 | + subId + "' for key:" + key); |
| 3415 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3416 | } |
| 3417 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3418 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3419 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3420 | + subId + "' for key:" + key); |
| 3421 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3422 | } finally { |
| 3423 | Binder.restoreCallingIdentity(identity); |
| 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | @Override |
| 3428 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3429 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3430 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3431 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3432 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3433 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 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, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3440 | + subId + "' for key:" + key); |
| 3441 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3442 | } |
| 3443 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
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, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3446 | + "' for key:" + key); |
| 3447 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
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 setImsProvisioningString(int subId, int key, String 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 | "setImsProvisioningString"); |
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, "setImsProvisioningString: 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, "setImsProvisioningString: 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 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3479 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3480 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3481 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3482 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3483 | } |
| 3484 | return slotId; |
| 3485 | } |
| 3486 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3487 | private int getSlotIndex(int subId) { |
| 3488 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3489 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3490 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3491 | } |
| 3492 | return slotId; |
| 3493 | } |
| 3494 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3495 | /** |
| 3496 | * Returns the network type for a subId |
| 3497 | */ |
| 3498 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3499 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3500 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3501 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3502 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3503 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3504 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3505 | final long identity = Binder.clearCallingIdentity(); |
| 3506 | try { |
| 3507 | final Phone phone = getPhone(subId); |
| 3508 | if (phone != null) { |
| 3509 | return phone.getServiceState().getDataNetworkType(); |
| 3510 | } else { |
| 3511 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3512 | } |
| 3513 | } finally { |
| 3514 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3515 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | /** |
| 3519 | * Returns the data network type |
| 3520 | */ |
| 3521 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3522 | public int getDataNetworkType(String callingPackage) { |
| 3523 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | /** |
| 3527 | * Returns the data network type for a subId |
| 3528 | */ |
| 3529 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3530 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3531 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3532 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3533 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3534 | } |
| 3535 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | final long identity = Binder.clearCallingIdentity(); |
| 3537 | try { |
| 3538 | final Phone phone = getPhone(subId); |
| 3539 | if (phone != null) { |
| 3540 | return phone.getServiceState().getDataNetworkType(); |
| 3541 | } else { |
| 3542 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3543 | } |
| 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3550 | * Returns the Voice network type for a subId |
| 3551 | */ |
| 3552 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3553 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3554 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3555 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3556 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3557 | } |
| 3558 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3559 | final long identity = Binder.clearCallingIdentity(); |
| 3560 | try { |
| 3561 | final Phone phone = getPhone(subId); |
| 3562 | if (phone != null) { |
| 3563 | return phone.getServiceState().getVoiceNetworkType(); |
| 3564 | } else { |
| 3565 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3566 | } |
| 3567 | } finally { |
| 3568 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * @return true if a ICC card is present |
| 3574 | */ |
| 3575 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3576 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3577 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3578 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3582 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3583 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3584 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3585 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3586 | final long identity = Binder.clearCallingIdentity(); |
| 3587 | try { |
| 3588 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3589 | if (phone != null) { |
| 3590 | return phone.getIccCard().hasIccCard(); |
| 3591 | } else { |
| 3592 | return false; |
| 3593 | } |
| 3594 | } finally { |
| 3595 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3596 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | /** |
| 3600 | * Return if the current radio is LTE on CDMA. This |
| 3601 | * is a tri-state return value as for a period of time |
| 3602 | * the mode may be unknown. |
| 3603 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3604 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3605 | * @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] | 3606 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3607 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3608 | @Override |
| 3609 | public int getLteOnCdmaMode(String callingPackage) { |
| 3610 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3611 | } |
| 3612 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3613 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3614 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3615 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3616 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3617 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3618 | } |
| 3619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3620 | final long identity = Binder.clearCallingIdentity(); |
| 3621 | try { |
| 3622 | final Phone phone = getPhone(subId); |
| 3623 | if (phone == null) { |
| 3624 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3625 | } else { |
| 3626 | return phone.getLteOnCdmaMode(); |
| 3627 | } |
| 3628 | } finally { |
| 3629 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3630 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3633 | /** |
| 3634 | * {@hide} |
| 3635 | * Returns Default subId, 0 in the case of single standby. |
| 3636 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3637 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3638 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3641 | private int getSlotForDefaultSubscription() { |
| 3642 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3643 | } |
| 3644 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3645 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3646 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3647 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3648 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3649 | private boolean isActiveSubscription(int subId) { |
| 3650 | return mSubscriptionController.isActiveSubId(subId); |
| 3651 | } |
| 3652 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3653 | /** |
| 3654 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3655 | */ |
| 3656 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3657 | final long identity = Binder.clearCallingIdentity(); |
| 3658 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3659 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3661 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3662 | } finally { |
| 3663 | Binder.restoreCallingIdentity(identity); |
| 3664 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | /** |
| 3668 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3669 | */ |
| 3670 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3671 | final long identity = Binder.clearCallingIdentity(); |
| 3672 | try { |
| 3673 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3674 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3675 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3676 | } finally { |
| 3677 | Binder.restoreCallingIdentity(identity); |
| 3678 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3679 | } |
| 3680 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3681 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3682 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3683 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3684 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3685 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3686 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3687 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3688 | if (phoneId == -1) { |
| 3689 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3690 | + " does not correspond to an active phone"); |
| 3691 | } |
| 3692 | return PhoneFactory.getPhone(phoneId); |
| 3693 | } |
| 3694 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3695 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3696 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3697 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3699 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3700 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3701 | if (DBG) { |
| 3702 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3703 | } |
| 3704 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3705 | p2); |
| 3706 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3707 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3708 | |
| 3709 | @Override |
| 3710 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3711 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3712 | enforceModifyPermission(); |
| 3713 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3714 | if (DBG) { |
| 3715 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3716 | } |
| 3717 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3718 | callingPackage, aid, p2); |
| 3719 | } |
| 3720 | |
| 3721 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3722 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3723 | final long identity = Binder.clearCallingIdentity(); |
| 3724 | try { |
| 3725 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3726 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3727 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3728 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3729 | if (bestComponent == null |
| 3730 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3731 | loge("The calling package is not allowed to access ISD-R."); |
| 3732 | throw new SecurityException( |
| 3733 | "The calling package is not allowed to access ISD-R."); |
| 3734 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3735 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3736 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3737 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3738 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3739 | null /* workSource */); |
| 3740 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3741 | return response; |
| 3742 | } finally { |
| 3743 | Binder.restoreCallingIdentity(identity); |
| 3744 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3748 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3750 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3751 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3752 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3753 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3754 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3755 | @Override |
| 3756 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3757 | enforceModifyPermission(); |
| 3758 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3759 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3760 | channel); |
| 3761 | } |
| 3762 | |
| 3763 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3764 | final long identity = Binder.clearCallingIdentity(); |
| 3765 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | if (channel < 0) { |
| 3767 | return false; |
| 3768 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3769 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3770 | null /* workSource */); |
| 3771 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3772 | return success; |
| 3773 | } finally { |
| 3774 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3775 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3779 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3780 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3782 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3783 | if (DBG) { |
| 3784 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3785 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3786 | + p3 + " data=" + data); |
| 3787 | } |
| 3788 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3789 | command, p1, p2, p3, data); |
| 3790 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3791 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3792 | @Override |
| 3793 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3794 | int command, int p1, int p2, int p3, String data) { |
| 3795 | enforceModifyPermission(); |
| 3796 | if (DBG) { |
| 3797 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3798 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3799 | + p3 + " data=" + data); |
| 3800 | } |
| 3801 | return iccTransmitApduLogicalChannelWithPermission( |
| 3802 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3803 | data); |
| 3804 | } |
| 3805 | |
| 3806 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3807 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3808 | final long identity = Binder.clearCallingIdentity(); |
| 3809 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3810 | if (channel < 0) { |
| 3811 | return ""; |
| 3812 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3813 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3814 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3815 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3816 | null /* workSource */); |
| 3817 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3818 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | // Append the returned status code to the end of the response payload. |
| 3820 | String s = Integer.toHexString( |
| 3821 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3822 | if (response.payload != null) { |
| 3823 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3824 | } |
| 3825 | return s; |
| 3826 | } finally { |
| 3827 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3828 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3829 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3830 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3831 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3832 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3833 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3834 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3835 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3836 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3837 | if (DBG) { |
| 3838 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3839 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3840 | } |
| 3841 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3842 | cla, command, p1, p2, p3, data); |
| 3843 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3844 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3845 | @Override |
| 3846 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3847 | int command, int p1, int p2, int p3, String data) { |
| 3848 | enforceModifyPermission(); |
| 3849 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3850 | if (DBG) { |
| 3851 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3852 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3853 | + " data=" + data); |
| 3854 | } |
| 3855 | |
| 3856 | return iccTransmitApduBasicChannelWithPermission( |
| 3857 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3858 | p2, p3, data); |
| 3859 | } |
| 3860 | |
| 3861 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3862 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3863 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3864 | final long identity = Binder.clearCallingIdentity(); |
| 3865 | try { |
| 3866 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3867 | && TextUtils.equals(ISDR_AID, data)) { |
| 3868 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3869 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3870 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3871 | if (bestComponent == null |
| 3872 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3873 | loge("The calling package is not allowed to select ISD-R."); |
| 3874 | throw new SecurityException( |
| 3875 | "The calling package is not allowed to select ISD-R."); |
| 3876 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3877 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3879 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3880 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3881 | null /* workSource */); |
| 3882 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3883 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3884 | // Append the returned status code to the end of the response payload. |
| 3885 | String s = Integer.toHexString( |
| 3886 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3887 | if (response.payload != null) { |
| 3888 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3889 | } |
| 3890 | return s; |
| 3891 | } finally { |
| 3892 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3893 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3894 | } |
| 3895 | |
| 3896 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3897 | 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] | 3898 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3899 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3900 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3901 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3902 | final long identity = Binder.clearCallingIdentity(); |
| 3903 | try { |
| 3904 | if (DBG) { |
| 3905 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3906 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3907 | } |
| 3908 | |
| 3909 | IccIoResult response = |
| 3910 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3911 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3912 | subId); |
| 3913 | |
| 3914 | if (DBG) { |
| 3915 | log("Exchange SIM_IO [R]" + response); |
| 3916 | } |
| 3917 | |
| 3918 | byte[] result = null; |
| 3919 | int length = 2; |
| 3920 | if (response.payload != null) { |
| 3921 | length = 2 + response.payload.length; |
| 3922 | result = new byte[length]; |
| 3923 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3924 | } else { |
| 3925 | result = new byte[length]; |
| 3926 | } |
| 3927 | |
| 3928 | result[length - 1] = (byte) response.sw2; |
| 3929 | result[length - 2] = (byte) response.sw1; |
| 3930 | return result; |
| 3931 | } finally { |
| 3932 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3933 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3936 | /** |
| 3937 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3938 | * on a particular subscription |
| 3939 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3940 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3941 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3942 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3943 | return null; |
| 3944 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3945 | |
| 3946 | final long identity = Binder.clearCallingIdentity(); |
| 3947 | try { |
| 3948 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3949 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3950 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3951 | return null; |
| 3952 | } |
| 3953 | Object response = sendRequest( |
| 3954 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3955 | if (response instanceof String[]) { |
| 3956 | return (String[]) response; |
| 3957 | } |
| 3958 | // Response is an Exception of some kind, |
| 3959 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3960 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3961 | } finally { |
| 3962 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3963 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3964 | } |
| 3965 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3966 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3967 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3969 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3970 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3971 | final long identity = Binder.clearCallingIdentity(); |
| 3972 | try { |
| 3973 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3974 | if (response.payload == null) { |
| 3975 | return ""; |
| 3976 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3977 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3978 | // Append the returned status code to the end of the response payload. |
| 3979 | String s = Integer.toHexString( |
| 3980 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3981 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3982 | return s; |
| 3983 | } finally { |
| 3984 | Binder.restoreCallingIdentity(identity); |
| 3985 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3988 | /** |
| 3989 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3990 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3991 | * |
| 3992 | * @param itemID the ID of the item to read |
| 3993 | * @return the NV item as a String, or null on error. |
| 3994 | */ |
| 3995 | @Override |
| 3996 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3997 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3998 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3999 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4000 | |
| 4001 | final long identity = Binder.clearCallingIdentity(); |
| 4002 | try { |
| 4003 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4004 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4005 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4006 | return value; |
| 4007 | } finally { |
| 4008 | Binder.restoreCallingIdentity(identity); |
| 4009 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | /** |
| 4013 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4014 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4015 | * |
| 4016 | * @param itemID the ID of the item to read |
| 4017 | * @param itemValue the value to write, as a String |
| 4018 | * @return true on success; false on any failure |
| 4019 | */ |
| 4020 | @Override |
| 4021 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4022 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4023 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4024 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4025 | |
| 4026 | final long identity = Binder.clearCallingIdentity(); |
| 4027 | try { |
| 4028 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4029 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4030 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4031 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4032 | return success; |
| 4033 | } finally { |
| 4034 | Binder.restoreCallingIdentity(identity); |
| 4035 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | /** |
| 4039 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4040 | * Used for device configuration by some CDMA operators. |
| 4041 | * |
| 4042 | * @param preferredRoamingList byte array containing the new PRL |
| 4043 | * @return true on success; false on any failure |
| 4044 | */ |
| 4045 | @Override |
| 4046 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4047 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4048 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4049 | |
| 4050 | final long identity = Binder.clearCallingIdentity(); |
| 4051 | try { |
| 4052 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4053 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4054 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4055 | return success; |
| 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(identity); |
| 4058 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4062 | * 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] | 4063 | * Used for device configuration by some CDMA operators. |
| 4064 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4065 | * @param slotIndex - device slot. |
| 4066 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4067 | * @return true on success; false on any failure |
| 4068 | */ |
| 4069 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4070 | public boolean resetModemConfig(int slotIndex) { |
| 4071 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4072 | if (phone != null) { |
| 4073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4074 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4075 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4076 | final long identity = Binder.clearCallingIdentity(); |
| 4077 | try { |
| 4078 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4079 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4080 | return success; |
| 4081 | } finally { |
| 4082 | Binder.restoreCallingIdentity(identity); |
| 4083 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4084 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4085 | return false; |
| 4086 | } |
| 4087 | |
| 4088 | /** |
| 4089 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4090 | * |
| 4091 | * @param slotIndex - device slot. |
| 4092 | * |
| 4093 | * @return true on success; false on any failure |
| 4094 | */ |
| 4095 | @Override |
| 4096 | public boolean rebootModem(int slotIndex) { |
| 4097 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4098 | if (phone != null) { |
| 4099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4100 | mApp, phone.getSubId(), "rebootModem"); |
| 4101 | |
| 4102 | final long identity = Binder.clearCallingIdentity(); |
| 4103 | try { |
| 4104 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4105 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4106 | return success; |
| 4107 | } finally { |
| 4108 | Binder.restoreCallingIdentity(identity); |
| 4109 | } |
| 4110 | } |
| 4111 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4112 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4113 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4114 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4115 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4116 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4117 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4118 | return new String[0]; |
| 4119 | } |
| 4120 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4121 | final long identity = Binder.clearCallingIdentity(); |
| 4122 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4123 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4124 | } finally { |
| 4125 | Binder.restoreCallingIdentity(identity); |
| 4126 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4127 | } |
| 4128 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4129 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4130 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4131 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4132 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4133 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4134 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4135 | |
| 4136 | final long identity = Binder.clearCallingIdentity(); |
| 4137 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4138 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4139 | if (resolver == null) { |
| 4140 | // may happen if the device does not support IMS. |
| 4141 | return; |
| 4142 | } |
| 4143 | resolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4144 | } finally { |
| 4145 | Binder.restoreCallingIdentity(identity); |
| 4146 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4150 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4151 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4152 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4153 | public void disableIms(int slotId) { |
| 4154 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4155 | |
| 4156 | final long identity = Binder.clearCallingIdentity(); |
| 4157 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4158 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4159 | if (resolver == null) { |
| 4160 | // may happen if the device does not support IMS. |
| 4161 | return; |
| 4162 | } |
| 4163 | resolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4164 | } finally { |
| 4165 | Binder.restoreCallingIdentity(identity); |
| 4166 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | /** |
| 4170 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4171 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4172 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4173 | */ |
| 4174 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4175 | IImsServiceFeatureCallback callback) { |
| 4176 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | |
| 4178 | final long identity = Binder.clearCallingIdentity(); |
| 4179 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4180 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4181 | if (resolver == null) { |
| 4182 | // may happen if the device does not support IMS. |
| 4183 | return null; |
| 4184 | } |
| 4185 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4186 | } finally { |
| 4187 | Binder.restoreCallingIdentity(identity); |
| 4188 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | /** |
| 4192 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4193 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4194 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4195 | * listener for feature updates. |
| 4196 | */ |
| 4197 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4198 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4199 | |
| 4200 | final long identity = Binder.clearCallingIdentity(); |
| 4201 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4202 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4203 | if (resolver == null) { |
| 4204 | // may happen if the device does not support IMS. |
| 4205 | return null; |
| 4206 | } |
| 4207 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4208 | } finally { |
| 4209 | Binder.restoreCallingIdentity(identity); |
| 4210 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4211 | } |
| 4212 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4213 | /** |
| 4214 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4215 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4216 | */ |
| 4217 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4219 | |
| 4220 | final long identity = Binder.clearCallingIdentity(); |
| 4221 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4222 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4223 | if (resolver == null) { |
| 4224 | // may happen if the device does not support IMS. |
| 4225 | return null; |
| 4226 | } |
| 4227 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(identity); |
| 4230 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4233 | /** |
| 4234 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4235 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4236 | */ |
| 4237 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4238 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4239 | |
| 4240 | final long identity = Binder.clearCallingIdentity(); |
| 4241 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4242 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4243 | if (resolver == null) { |
| 4244 | // may happen if the device does not support IMS. |
| 4245 | return null; |
| 4246 | } |
| 4247 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4248 | } finally { |
| 4249 | Binder.restoreCallingIdentity(identity); |
| 4250 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4251 | } |
| 4252 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4253 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4254 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4255 | * |
| 4256 | * @param slotId the slot ID that the ImsService should bind for. |
| 4257 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4258 | * ImsService is the device default ImsService. |
| 4259 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4260 | * to. |
| 4261 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4262 | * @hide |
| 4263 | */ |
| 4264 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4265 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4267 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4268 | "setImsService"); |
| 4269 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4270 | final long identity = Binder.clearCallingIdentity(); |
| 4271 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4272 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4273 | if (resolver == null) { |
| 4274 | // may happen if the device does not support IMS. |
| 4275 | return false; |
| 4276 | } |
| 4277 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4278 | packageName); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4279 | } finally { |
| 4280 | Binder.restoreCallingIdentity(identity); |
| 4281 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | /** |
| 4285 | * Return the ImsService configuration. |
| 4286 | * |
| 4287 | * @param slotId The slot that the ImsService is associated with. |
| 4288 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4289 | * the device default. |
| 4290 | * @return the package name of the ImsService configuration. |
| 4291 | */ |
| 4292 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4293 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4294 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4295 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4296 | "getImsService"); |
| 4297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4298 | final long identity = Binder.clearCallingIdentity(); |
| 4299 | try { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4300 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4301 | if (resolver == null) { |
| 4302 | // may happen if the device does not support IMS. |
| 4303 | return ""; |
| 4304 | } |
| 4305 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
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 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4311 | public void setImsRegistrationState(boolean registered) { |
| 4312 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4313 | |
| 4314 | final long identity = Binder.clearCallingIdentity(); |
| 4315 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4316 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4317 | } finally { |
| 4318 | Binder.restoreCallingIdentity(identity); |
| 4319 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4323 | * Set the network selection mode to automatic. |
| 4324 | * |
| 4325 | */ |
| 4326 | @Override |
| 4327 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4329 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4330 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4331 | if (!isActiveSubscription(subId)) { |
| 4332 | return; |
| 4333 | } |
| 4334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4335 | final long identity = Binder.clearCallingIdentity(); |
| 4336 | try { |
| 4337 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4338 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4339 | } finally { |
| 4340 | Binder.restoreCallingIdentity(identity); |
| 4341 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4342 | } |
| 4343 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4344 | /** |
| 4345 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4346 | * |
| 4347 | * @param subId the id of the subscription. |
| 4348 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4349 | * the operator to attach to. |
| 4350 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4351 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4352 | * normal network selection next time. |
| 4353 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4354 | */ |
| 4355 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4356 | public boolean setNetworkSelectionModeManual( |
| 4357 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4358 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4359 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4360 | |
| 4361 | if (!isActiveSubscription(subId)) { |
| 4362 | return false; |
| 4363 | } |
| 4364 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4365 | final long identity = Binder.clearCallingIdentity(); |
| 4366 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4367 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4368 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4369 | if (DBG) { |
| 4370 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4371 | + " operator: " + operatorInfo); |
| 4372 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4373 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4374 | } finally { |
| 4375 | Binder.restoreCallingIdentity(identity); |
| 4376 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | /** |
| 4380 | * Scans for available networks. |
| 4381 | */ |
| 4382 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4383 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4385 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4386 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4387 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4388 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4389 | .setCallingPackage(callingPackage) |
| 4390 | .setCallingPid(Binder.getCallingPid()) |
| 4391 | .setCallingUid(Binder.getCallingUid()) |
| 4392 | .setMethod("getCellNetworkScanResults") |
| 4393 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4394 | .build()); |
| 4395 | switch (locationResult) { |
| 4396 | case DENIED_HARD: |
| 4397 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4398 | case DENIED_SOFT: |
| 4399 | return null; |
| 4400 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4401 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4402 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4403 | try { |
| 4404 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4405 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4406 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | } finally { |
| 4408 | Binder.restoreCallingIdentity(identity); |
| 4409 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4413 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4414 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4415 | * @param subId id of the subscription |
| 4416 | * @param request contains the radio access networks with bands/channels to scan |
| 4417 | * @param messenger callback messenger for scan results or errors |
| 4418 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4419 | * @return the id of the requested scan which can be used to stop the scan. |
| 4420 | */ |
| 4421 | @Override |
| 4422 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4423 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4424 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4425 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4426 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4427 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4428 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4429 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4430 | .setCallingPackage(callingPackage) |
| 4431 | .setCallingPid(Binder.getCallingPid()) |
| 4432 | .setCallingUid(Binder.getCallingUid()) |
| 4433 | .setMethod("requestNetworkScan") |
| 4434 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4435 | .build()); |
| 4436 | switch (locationResult) { |
| 4437 | case DENIED_HARD: |
| 4438 | throw new SecurityException("Not allowed to request network scan -- location"); |
| 4439 | case DENIED_SOFT: |
| 4440 | return -1; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4441 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4442 | |
| 4443 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4444 | request, messenger, binder, getPhone(subId), |
| 4445 | callingPackage); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | /** |
| 4449 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4450 | * |
| 4451 | * @param subId id of the subscription |
| 4452 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4453 | */ |
| 4454 | @Override |
| 4455 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4456 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4457 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4458 | |
| 4459 | final long identity = Binder.clearCallingIdentity(); |
| 4460 | try { |
| 4461 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4462 | } finally { |
| 4463 | Binder.restoreCallingIdentity(identity); |
| 4464 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4468 | * Get the calculated preferred network type. |
| 4469 | * Used for debugging incorrect network type. |
| 4470 | * |
| 4471 | * @return the preferred network type, defined in RILConstants.java. |
| 4472 | */ |
| 4473 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4474 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4475 | final Phone defaultPhone = getDefaultPhone(); |
| 4476 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4477 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4478 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4479 | } |
| 4480 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4481 | final long identity = Binder.clearCallingIdentity(); |
| 4482 | try { |
| 4483 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4484 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
| 4487 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4491 | * Get the preferred network type. |
| 4492 | * Used for device configuration by some CDMA operators. |
| 4493 | * |
| 4494 | * @return the preferred network type, defined in RILConstants.java. |
| 4495 | */ |
| 4496 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4497 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4498 | TelephonyPermissions |
| 4499 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4500 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4501 | |
| 4502 | final long identity = Binder.clearCallingIdentity(); |
| 4503 | try { |
| 4504 | if (DBG) log("getPreferredNetworkType"); |
| 4505 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4506 | int networkType = (result != null ? result[0] : -1); |
| 4507 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4508 | return networkType; |
| 4509 | } finally { |
| 4510 | Binder.restoreCallingIdentity(identity); |
| 4511 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | /** |
| 4515 | * Set the preferred network type. |
| 4516 | * Used for device configuration by some CDMA operators. |
| 4517 | * |
| 4518 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4519 | * @return true on success; false on any failure. |
| 4520 | */ |
| 4521 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4522 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4524 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | |
| 4526 | final long identity = Binder.clearCallingIdentity(); |
| 4527 | try { |
| 4528 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4529 | Boolean success = (Boolean) sendRequest( |
| 4530 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4531 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4532 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4533 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4534 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4535 | } |
| 4536 | return success; |
| 4537 | } finally { |
| 4538 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4539 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4540 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4541 | |
| 4542 | /** |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4543 | * Check whether DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4544 | * |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4545 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4546 | * @hide |
| 4547 | */ |
| 4548 | @Override |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4549 | public boolean getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4550 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4551 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4552 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4553 | try { |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4554 | return defaultPhone.hasMatchedTetherApnSetting(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4555 | } finally { |
| 4556 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4557 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4561 | * Set mobile data enabled |
| 4562 | * Used by the user through settings etc to turn on/off mobile data |
| 4563 | * |
| 4564 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4565 | */ |
| 4566 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4567 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4569 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4570 | |
| 4571 | final long identity = Binder.clearCallingIdentity(); |
| 4572 | try { |
| 4573 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4574 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4575 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4576 | if (phone != null) { |
| 4577 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4578 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4579 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4580 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4581 | } |
| 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4584 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4588 | * Get the user enabled state of Mobile Data. |
| 4589 | * |
| 4590 | * TODO: remove and use isUserDataEnabled. |
| 4591 | * This can't be removed now because some vendor codes |
| 4592 | * calls through ITelephony directly while they should |
| 4593 | * use TelephonyManager. |
| 4594 | * |
| 4595 | * @return true on enabled |
| 4596 | */ |
| 4597 | @Override |
| 4598 | public boolean getDataEnabled(int subId) { |
| 4599 | return isUserDataEnabled(subId); |
| 4600 | } |
| 4601 | |
| 4602 | /** |
| 4603 | * Get whether mobile data is enabled per user setting. |
| 4604 | * |
| 4605 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4606 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4607 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4608 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4609 | * |
| 4610 | * @return {@code true} if data is enabled else {@code false} |
| 4611 | */ |
| 4612 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4613 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4614 | try { |
| 4615 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4616 | null); |
| 4617 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4619 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4620 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4621 | |
| 4622 | final long identity = Binder.clearCallingIdentity(); |
| 4623 | try { |
| 4624 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4625 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4626 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4627 | if (phone != null) { |
| 4628 | boolean retVal = phone.isUserDataEnabled(); |
| 4629 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4630 | return retVal; |
| 4631 | } else { |
| 4632 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4633 | return false; |
| 4634 | } |
| 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | |
| 4640 | /** |
| 4641 | * Get whether mobile data is enabled. |
| 4642 | * |
| 4643 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4644 | * whether mobile data is actually enabled. |
| 4645 | * |
| 4646 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4647 | * |
| 4648 | * @return {@code true} if data is enabled else {@code false} |
| 4649 | */ |
| 4650 | @Override |
| 4651 | public boolean isDataEnabled(int subId) { |
| 4652 | try { |
| 4653 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4654 | null); |
| 4655 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4656 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4657 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4658 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4659 | |
| 4660 | final long identity = Binder.clearCallingIdentity(); |
| 4661 | try { |
| 4662 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4663 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4664 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4665 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4666 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4667 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4668 | return retVal; |
| 4669 | } else { |
| 4670 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4671 | return false; |
| 4672 | } |
| 4673 | } finally { |
| 4674 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4675 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4676 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4677 | |
| 4678 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4679 | public int getCarrierPrivilegeStatus(int subId) { |
| 4680 | final Phone phone = getPhone(subId); |
| 4681 | if (phone == null) { |
| 4682 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4683 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4684 | } |
| 4685 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4686 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4687 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4688 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4689 | } |
| 4690 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4691 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4692 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4693 | |
| 4694 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4695 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 4696 | final Phone phone = getPhone(subId); |
| 4697 | if (phone == null) { |
| 4698 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4699 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4700 | } |
| 4701 | UiccProfile profile = |
| 4702 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4703 | if (profile == null) { |
| 4704 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4705 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4706 | } |
| 4707 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4708 | } |
| 4709 | |
| 4710 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4711 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4712 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4713 | if (TextUtils.isEmpty(pkgName)) |
| 4714 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4715 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4716 | if (card == null) { |
| 4717 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4718 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4719 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4720 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4721 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | @Override |
| 4725 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4726 | if (TextUtils.isEmpty(pkgName)) |
| 4727 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4728 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4729 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4730 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4731 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4732 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4733 | continue; |
| 4734 | } |
| 4735 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4736 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4737 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4738 | break; |
| 4739 | } |
| 4740 | } |
| 4741 | |
| 4742 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4743 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4744 | |
| 4745 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4746 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4747 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4748 | loge("phoneId " + phoneId + " is not valid."); |
| 4749 | return null; |
| 4750 | } |
| 4751 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4752 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4753 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4754 | return null ; |
| 4755 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4756 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4757 | } |
| 4758 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4759 | @Override |
| 4760 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4761 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4762 | List<String> privilegedPackages = new ArrayList<>(); |
| 4763 | List<PackageInfo> packages = null; |
| 4764 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4765 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4766 | if (card == null) { |
| 4767 | // No UICC in that slot. |
| 4768 | continue; |
| 4769 | } |
| 4770 | if (card.hasCarrierPrivilegeRules()) { |
| 4771 | if (packages == null) { |
| 4772 | // Only check packages in user 0 for now |
| 4773 | packages = pm.getInstalledPackagesAsUser( |
| 4774 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4775 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4776 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4777 | } |
| 4778 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4779 | PackageInfo pkgInfo = packages.get(p); |
| 4780 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4781 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4782 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4783 | privilegedPackages.add(pkgInfo.packageName); |
| 4784 | } |
| 4785 | } |
| 4786 | } |
| 4787 | } |
| 4788 | return privilegedPackages; |
| 4789 | } |
| 4790 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4791 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4792 | final Phone phone = getPhone(subId); |
| 4793 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4794 | if (card == null) { |
| 4795 | loge("getIccId: No UICC"); |
| 4796 | return null; |
| 4797 | } |
| 4798 | String iccId = card.getIccId(); |
| 4799 | if (TextUtils.isEmpty(iccId)) { |
| 4800 | loge("getIccId: ICC ID is null or empty."); |
| 4801 | return null; |
| 4802 | } |
| 4803 | return iccId; |
| 4804 | } |
| 4805 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4806 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4807 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4808 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4809 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4810 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4811 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4812 | final long identity = Binder.clearCallingIdentity(); |
| 4813 | try { |
| 4814 | final String iccId = getIccId(subId); |
| 4815 | final Phone phone = getPhone(subId); |
| 4816 | if (phone == null) { |
| 4817 | return false; |
| 4818 | } |
| 4819 | final String subscriberId = phone.getSubscriberId(); |
| 4820 | |
| 4821 | if (DBG_MERGE) { |
| 4822 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4823 | + subscriberId + " to " + number); |
| 4824 | } |
| 4825 | |
| 4826 | if (TextUtils.isEmpty(iccId)) { |
| 4827 | return false; |
| 4828 | } |
| 4829 | |
| 4830 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4831 | |
| 4832 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4833 | if (alphaTag == null) { |
| 4834 | editor.remove(alphaTagPrefKey); |
| 4835 | } else { |
| 4836 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4837 | } |
| 4838 | |
| 4839 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4840 | // track all merged IMSIs based on line number |
| 4841 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4842 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4843 | if (number == null) { |
| 4844 | editor.remove(numberPrefKey); |
| 4845 | editor.remove(subscriberPrefKey); |
| 4846 | } else { |
| 4847 | editor.putString(numberPrefKey, number); |
| 4848 | editor.putString(subscriberPrefKey, subscriberId); |
| 4849 | } |
| 4850 | |
| 4851 | editor.commit(); |
| 4852 | return true; |
| 4853 | } finally { |
| 4854 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4855 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4859 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4860 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4861 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4862 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4863 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4864 | return null; |
| 4865 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4866 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4867 | final long identity = Binder.clearCallingIdentity(); |
| 4868 | try { |
| 4869 | String iccId = getIccId(subId); |
| 4870 | if (iccId != null) { |
| 4871 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4872 | if (DBG_MERGE) { |
| 4873 | log("getLine1NumberForDisplay returning " |
| 4874 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4875 | } |
| 4876 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4878 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4879 | return null; |
| 4880 | } finally { |
| 4881 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4882 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4886 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4887 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4888 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4889 | return null; |
| 4890 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4891 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4892 | final long identity = Binder.clearCallingIdentity(); |
| 4893 | try { |
| 4894 | String iccId = getIccId(subId); |
| 4895 | if (iccId != null) { |
| 4896 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4897 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4898 | } |
| 4899 | return null; |
| 4900 | } finally { |
| 4901 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4902 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4903 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4904 | |
| 4905 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4906 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4907 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4908 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4909 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4910 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4911 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4912 | return null; |
| 4913 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4914 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4915 | final long identity = Binder.clearCallingIdentity(); |
| 4916 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4917 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4918 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4919 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4920 | |
| 4921 | // Figure out what subscribers are currently active |
| 4922 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4923 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4924 | // the process, where TelephonyManager was instantiated. |
| 4925 | // Otherwise AppOps check will fail. |
| 4926 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4927 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4928 | for (int subId : subIds) { |
| 4929 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4930 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | |
| 4932 | // First pass, find a number override for an active subscriber |
| 4933 | String mergeNumber = null; |
| 4934 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4935 | for (String key : prefs.keySet()) { |
| 4936 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4937 | final String subscriberId = (String) prefs.get(key); |
| 4938 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4939 | final String iccId = key.substring( |
| 4940 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4941 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4942 | mergeNumber = (String) prefs.get(numberKey); |
| 4943 | if (DBG_MERGE) { |
| 4944 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4945 | + " for active subscriber " + subscriberId); |
| 4946 | } |
| 4947 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4948 | break; |
| 4949 | } |
| 4950 | } |
| 4951 | } |
| 4952 | } |
| 4953 | |
| 4954 | // Shortcut when no active merged subscribers |
| 4955 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4956 | return null; |
| 4957 | } |
| 4958 | |
| 4959 | // Second pass, find all subscribers under that line override |
| 4960 | final ArraySet<String> result = new ArraySet<>(); |
| 4961 | for (String key : prefs.keySet()) { |
| 4962 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4963 | final String number = (String) prefs.get(key); |
| 4964 | if (mergeNumber.equals(number)) { |
| 4965 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4966 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4967 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4968 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4969 | result.add(subscriberId); |
| 4970 | } |
| 4971 | } |
| 4972 | } |
| 4973 | } |
| 4974 | |
| 4975 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4976 | Arrays.sort(resultArray); |
| 4977 | if (DBG_MERGE) { |
| 4978 | Slog.d(LOG_TAG, |
| 4979 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4980 | } |
| 4981 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4982 | } finally { |
| 4983 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4984 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4988 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4989 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4990 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4991 | |
| 4992 | final long identity = Binder.clearCallingIdentity(); |
| 4993 | try { |
| 4994 | final Phone phone = getPhone(subId); |
| 4995 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
| 4998 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4999 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5000 | |
| 5001 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5002 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5003 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5004 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5005 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5006 | |
| 5007 | final long identity = Binder.clearCallingIdentity(); |
| 5008 | try { |
| 5009 | final Phone phone = getPhone(subId); |
| 5010 | if (phone == null) { |
| 5011 | return false; |
| 5012 | } |
| 5013 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5014 | cdmaNonRoamingList); |
| 5015 | } finally { |
| 5016 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5017 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5021 | @Deprecated |
| 5022 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5023 | enforceModifyPermission(); |
| 5024 | |
| 5025 | int returnValue = 0; |
| 5026 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5027 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5028 | if(result.exception == null) { |
| 5029 | if (result.result != null) { |
| 5030 | byte[] responseData = (byte[])(result.result); |
| 5031 | if(responseData.length > oemResp.length) { |
| 5032 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5033 | responseData.length + "bytes. Buffer Size is " + |
| 5034 | oemResp.length + "bytes."); |
| 5035 | } |
| 5036 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5037 | returnValue = responseData.length; |
| 5038 | } |
| 5039 | } else { |
| 5040 | CommandException ex = (CommandException) result.exception; |
| 5041 | returnValue = ex.getCommandError().ordinal(); |
| 5042 | if(returnValue > 0) returnValue *= -1; |
| 5043 | } |
| 5044 | } catch (RuntimeException e) { |
| 5045 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5046 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5047 | if(returnValue > 0) returnValue *= -1; |
| 5048 | } |
| 5049 | |
| 5050 | return returnValue; |
| 5051 | } |
| 5052 | |
| 5053 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5054 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5055 | try { |
| 5056 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5057 | } catch (RuntimeException e) { |
| 5058 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5059 | } |
| 5060 | } |
| 5061 | |
| 5062 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5063 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5064 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5065 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5066 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5067 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5068 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | final long identity = Binder.clearCallingIdentity(); |
| 5070 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5071 | TelephonyPermissions |
| 5072 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5073 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5074 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5075 | } finally { |
| 5076 | Binder.restoreCallingIdentity(identity); |
| 5077 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5078 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5079 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5080 | |
| 5081 | @Override |
| 5082 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5083 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5084 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | |
| 5086 | final long identity = Binder.clearCallingIdentity(); |
| 5087 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5088 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5089 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
| 5092 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5096 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5097 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5098 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5099 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5100 | return false; |
| 5101 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5102 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5103 | final long identity = Binder.clearCallingIdentity(); |
| 5104 | try { |
| 5105 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5106 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5107 | // In the long run, we may instead need to check if there exists a connection service |
| 5108 | // which can support video calling. |
| 5109 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5110 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5111 | return imsManager.isVtEnabledByPlatform() |
| 5112 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5113 | && imsManager.isVtEnabledByUser(); |
| 5114 | } finally { |
| 5115 | Binder.restoreCallingIdentity(identity); |
| 5116 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5117 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5118 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5119 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5120 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5121 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5122 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5123 | return false; |
| 5124 | } |
| 5125 | |
| 5126 | final long identity = Binder.clearCallingIdentity(); |
| 5127 | try { |
| 5128 | CarrierConfigManager configManager = |
| 5129 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5130 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5131 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5132 | } finally { |
| 5133 | Binder.restoreCallingIdentity(identity); |
| 5134 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | @Override |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5139 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5140 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5141 | return false; |
| 5142 | } |
| 5143 | |
| 5144 | final long identity = Binder.clearCallingIdentity(); |
| 5145 | try { |
| 5146 | CarrierConfigManager configManager = |
| 5147 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5148 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(identity); |
| 5152 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5153 | } |
| 5154 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5155 | @Override |
| 5156 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5157 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5158 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | @Override |
| 5162 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | final long identity = Binder.clearCallingIdentity(); |
| 5164 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5165 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5166 | } finally { |
| 5167 | Binder.restoreCallingIdentity(identity); |
| 5168 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5169 | } |
| 5170 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5171 | /** |
| 5172 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5173 | * support for the feature and device firmware support. |
| 5174 | * |
| 5175 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5176 | */ |
| 5177 | @Override |
| 5178 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5180 | final Phone phone = getPhone(subscriptionId); |
| 5181 | if (phone == null) { |
| 5182 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5183 | return false; |
| 5184 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5185 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5186 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5188 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5189 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5190 | return isCarrierSupported && isDeviceSupported; |
| 5191 | } finally { |
| 5192 | Binder.restoreCallingIdentity(identity); |
| 5193 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5194 | } |
| 5195 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5196 | /** |
| 5197 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5198 | * both also support RTT. |
| 5199 | */ |
| 5200 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5201 | final long identity = Binder.clearCallingIdentity(); |
| 5202 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5203 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5204 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | } finally { |
| 5206 | Binder.restoreCallingIdentity(identity); |
| 5207 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5208 | } |
| 5209 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5210 | /** |
| 5211 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5212 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5213 | * |
| 5214 | * <p>Requires Permission: |
| 5215 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5216 | */ |
| 5217 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5218 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5219 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5220 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5221 | return null; |
| 5222 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5223 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5224 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
| 5225 | callingPackage, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5226 | return null; |
| 5227 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | |
| 5229 | final long identity = Binder.clearCallingIdentity(); |
| 5230 | try { |
| 5231 | return phone.getDeviceId(); |
| 5232 | } finally { |
| 5233 | Binder.restoreCallingIdentity(identity); |
| 5234 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5235 | } |
| 5236 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5237 | /** |
| 5238 | * {@hide} |
| 5239 | * Returns the IMS Registration Status on a particular subid |
| 5240 | * |
| 5241 | * @param subId |
| 5242 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5243 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5244 | Phone phone = getPhone(subId); |
| 5245 | if (phone != null) { |
| 5246 | return phone.isImsRegistered(); |
| 5247 | } else { |
| 5248 | return false; |
| 5249 | } |
| 5250 | } |
| 5251 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5252 | @Override |
| 5253 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5254 | final long identity = Binder.clearCallingIdentity(); |
| 5255 | try { |
| 5256 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5257 | } finally { |
| 5258 | Binder.restoreCallingIdentity(identity); |
| 5259 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5260 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5261 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5262 | /** |
| 5263 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5264 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5265 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5266 | final long identity = Binder.clearCallingIdentity(); |
| 5267 | try { |
| 5268 | Phone phone = getPhone(subId); |
| 5269 | if (phone != null) { |
| 5270 | return phone.isWifiCallingEnabled(); |
| 5271 | } else { |
| 5272 | return false; |
| 5273 | } |
| 5274 | } finally { |
| 5275 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5276 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5277 | } |
| 5278 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5279 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5280 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5281 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5282 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5283 | final long identity = Binder.clearCallingIdentity(); |
| 5284 | try { |
| 5285 | Phone phone = getPhone(subId); |
| 5286 | if (phone != null) { |
| 5287 | return phone.isVideoEnabled(); |
| 5288 | } else { |
| 5289 | return false; |
| 5290 | } |
| 5291 | } finally { |
| 5292 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5293 | } |
| 5294 | } |
| 5295 | |
| 5296 | /** |
| 5297 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5298 | * defined in {@link ImsRegistrationImplBase}. |
| 5299 | */ |
| 5300 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5301 | final long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
| 5303 | Phone phone = getPhone(subId); |
| 5304 | if (phone != null) { |
| 5305 | return phone.getImsRegistrationTech(); |
| 5306 | } else { |
| 5307 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5308 | } |
| 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5311 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5314 | @Override |
| 5315 | public void factoryReset(int subId) { |
| 5316 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5317 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5318 | return; |
| 5319 | } |
| 5320 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5321 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5322 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5323 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5324 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5325 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5326 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5327 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5328 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5329 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5330 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5331 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5332 | // There has been issues when Sms raw table somehow stores orphan |
| 5333 | // fragments. They lead to garbled message when new fragments come |
| 5334 | // in and combined with those stale ones. In case this happens again, |
| 5335 | // user can reset all network settings which will clean up this table. |
| 5336 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5337 | } finally { |
| 5338 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5339 | } |
| 5340 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5341 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5342 | private void cleanUpSmsRawTable(Context context) { |
| 5343 | ContentResolver resolver = context.getContentResolver(); |
| 5344 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5345 | resolver.delete(uri, null, null); |
| 5346 | } |
| 5347 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5348 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5349 | public String getSimLocaleForSubscriber(int subId) { |
| 5350 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5351 | final Phone phone = getPhone(subId); |
| 5352 | if (phone == null) { |
| 5353 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 5354 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5355 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5356 | final long identity = Binder.clearCallingIdentity(); |
| 5357 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5358 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5359 | phone.getContext().getOpPackageName()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 5360 | if (info == null) { |
| 5361 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 5362 | return null; |
| 5363 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5364 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5365 | // preferences (EF-PL and EF-LI)... |
| 5366 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5367 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5368 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5369 | if (localeFromDefaultSim != null) { |
| 5370 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5371 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5372 | + localeFromDefaultSim); |
| 5373 | return localeFromDefaultSim.toLanguageTag(); |
| 5374 | } else { |
| 5375 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | } |
| 5377 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5380 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5381 | // the SIM and carrier preferences does not include a country we add the country |
| 5382 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5383 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5385 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5386 | return mccLocale.toLanguageTag(); |
| 5387 | } |
| 5388 | |
| 5389 | if (DBG) log("No locale found - returning null"); |
| 5390 | return null; |
| 5391 | } finally { |
| 5392 | Binder.restoreCallingIdentity(identity); |
| 5393 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5397 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5398 | } |
| 5399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5400 | /** |
| 5401 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5402 | */ |
| 5403 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5404 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5405 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5406 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5407 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5408 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5409 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5410 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5411 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5412 | * representing the state of the modem. |
| 5413 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5414 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5415 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5416 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5417 | */ |
| 5418 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5419 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5420 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5421 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | |
| 5423 | final long identity = Binder.clearCallingIdentity(); |
| 5424 | try { |
| 5425 | ModemActivityInfo ret = null; |
| 5426 | synchronized (mLastModemActivityInfo) { |
| 5427 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5428 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5429 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5430 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5432 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5433 | mergedTxTimeMs[i] = info.getTxTimeMillis()[i] |
| 5434 | + mLastModemActivityInfo.getTxTimeMillis()[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5435 | } |
| 5436 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5437 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 5438 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5439 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5440 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5441 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5442 | mLastModemActivityInfo.setRxTimeMillis( |
| 5443 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5444 | mLastModemActivityInfo.setEnergyUsed( |
| 5445 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5446 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5448 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5449 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5450 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5451 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5452 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5453 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5454 | Bundle bundle = new Bundle(); |
| 5455 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5456 | result.send(0, bundle); |
| 5457 | } finally { |
| 5458 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5459 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5460 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5461 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5462 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5463 | // less than total activity duration. |
| 5464 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5465 | if (info == null) { |
| 5466 | return false; |
| 5467 | } |
| 5468 | int activityDurationMs = |
| 5469 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5470 | int totalTxTimeMs = 0; |
| 5471 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5472 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5473 | } |
| 5474 | return (info.isValid() |
| 5475 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5476 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5477 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5478 | && (totalTxTimeMs <= activityDurationMs)); |
| 5479 | } |
| 5480 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5481 | /** |
| 5482 | * {@hide} |
| 5483 | * Returns the service state information on specified subscription. |
| 5484 | */ |
| 5485 | @Override |
| 5486 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5487 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5488 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5489 | return null; |
| 5490 | } |
| 5491 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5492 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5493 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5494 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5495 | .setCallingPackage(callingPackage) |
| 5496 | .setCallingPid(Binder.getCallingPid()) |
| 5497 | .setCallingUid(Binder.getCallingUid()) |
| 5498 | .setMethod("getServiceStateForSubscriber") |
| 5499 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5500 | .build()); |
| 5501 | |
| 5502 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5503 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5504 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5505 | .setCallingPackage(callingPackage) |
| 5506 | .setCallingPid(Binder.getCallingPid()) |
| 5507 | .setCallingUid(Binder.getCallingUid()) |
| 5508 | .setMethod("getServiceStateForSubscriber") |
| 5509 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5510 | .build()); |
| 5511 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5512 | boolean hasFinePermission = |
| 5513 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5514 | boolean hasCoarsePermission = |
| 5515 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5516 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5517 | final long identity = Binder.clearCallingIdentity(); |
| 5518 | try { |
| 5519 | final Phone phone = getPhone(subId); |
| 5520 | if (phone == null) { |
| 5521 | return null; |
| 5522 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5523 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5524 | ServiceState ss = phone.getServiceState(); |
| 5525 | |
| 5526 | // Scrub out the location info in ServiceState depending on what level of access |
| 5527 | // the caller has. |
| 5528 | if (hasFinePermission) return ss; |
| 5529 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5530 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5531 | } finally { |
| 5532 | Binder.restoreCallingIdentity(identity); |
| 5533 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5534 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5535 | |
| 5536 | /** |
| 5537 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5538 | * |
| 5539 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5540 | * voicemail ringtone. |
| 5541 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5542 | * PhoneAccount. |
| 5543 | */ |
| 5544 | @Override |
| 5545 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5546 | final long identity = Binder.clearCallingIdentity(); |
| 5547 | try { |
| 5548 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5549 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5550 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5551 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5552 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5553 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5554 | } finally { |
| 5555 | Binder.restoreCallingIdentity(identity); |
| 5556 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5557 | } |
| 5558 | |
| 5559 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5560 | * Sets the per-account voicemail ringtone. |
| 5561 | * |
| 5562 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5563 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5564 | * |
| 5565 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5566 | * voicemail ringtone. |
| 5567 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5568 | * PhoneAccount. |
| 5569 | */ |
| 5570 | @Override |
| 5571 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5572 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5573 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5574 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5575 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5576 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5577 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5578 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5579 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5580 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | |
| 5582 | final long identity = Binder.clearCallingIdentity(); |
| 5583 | try { |
| 5584 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5585 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5586 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5587 | } |
| 5588 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5589 | } finally { |
| 5590 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5591 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5595 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5596 | * |
| 5597 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5598 | * voicemail vibration setting. |
| 5599 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5600 | */ |
| 5601 | @Override |
| 5602 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5603 | final long identity = Binder.clearCallingIdentity(); |
| 5604 | try { |
| 5605 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5606 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5607 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5608 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5609 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5610 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5611 | } finally { |
| 5612 | Binder.restoreCallingIdentity(identity); |
| 5613 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5614 | } |
| 5615 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5616 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5617 | * Sets the per-account voicemail vibration. |
| 5618 | * |
| 5619 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5620 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5621 | * |
| 5622 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5623 | * voicemail vibration setting. |
| 5624 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5625 | * specific PhoneAccount. |
| 5626 | */ |
| 5627 | @Override |
| 5628 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5629 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5630 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5631 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5632 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5633 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5635 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5636 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5637 | } |
| 5638 | |
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(phoneAccountHandle); |
| 5642 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5643 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | } |
| 5645 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5646 | } finally { |
| 5647 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5648 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5652 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5653 | * |
| 5654 | * @throws SecurityException if the caller does not have the required permission |
| 5655 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5656 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5657 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5658 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5662 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5663 | * permission. |
| 5664 | * |
| 5665 | * @throws SecurityException if the caller does not have the required permission |
| 5666 | */ |
| 5667 | private void enforceSendSmsPermission() { |
| 5668 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5669 | } |
| 5670 | |
| 5671 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5672 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5673 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5674 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5675 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5676 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | final long identity = Binder.clearCallingIdentity(); |
| 5678 | try { |
| 5679 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5680 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | if (componentName == null) { |
| 5682 | throw new SecurityException( |
| 5683 | "Caller not current active visual voicemail package[null]"); |
| 5684 | } |
| 5685 | String vvmPackage = componentName.getPackageName(); |
| 5686 | if (!callingPackage.equals(vvmPackage)) { |
| 5687 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5688 | + vvmPackage + "]"); |
| 5689 | } |
| 5690 | } finally { |
| 5691 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5692 | } |
| 5693 | } |
| 5694 | |
| 5695 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5696 | * Return the application ID for the app type. |
| 5697 | * |
| 5698 | * @param subId the subscription ID that this request applies to. |
| 5699 | * @param appType the uicc app type. |
| 5700 | * @return Application ID for specificied app type, or null if no uicc. |
| 5701 | */ |
| 5702 | @Override |
| 5703 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5704 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5705 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5706 | |
| 5707 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5708 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5709 | if (phone == null) { |
| 5710 | return null; |
| 5711 | } |
| 5712 | String aid = null; |
| 5713 | try { |
| 5714 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5715 | .getApplicationByType(appType).getAid(); |
| 5716 | } catch (Exception e) { |
| 5717 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5718 | } |
| 5719 | return aid; |
| 5720 | } finally { |
| 5721 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5722 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5723 | } |
| 5724 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5725 | /** |
| 5726 | * Return the Electronic Serial Number. |
| 5727 | * |
| 5728 | * @param subId the subscription ID that this request applies to. |
| 5729 | * @return ESN or null if error. |
| 5730 | */ |
| 5731 | @Override |
| 5732 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5733 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5734 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5735 | |
| 5736 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5737 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5738 | if (phone == null) { |
| 5739 | return null; |
| 5740 | } |
| 5741 | String esn = null; |
| 5742 | try { |
| 5743 | esn = phone.getEsn(); |
| 5744 | } catch (Exception e) { |
| 5745 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5746 | } |
| 5747 | return esn; |
| 5748 | } finally { |
| 5749 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5750 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5751 | } |
| 5752 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5753 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5754 | * Return the Preferred Roaming List Version. |
| 5755 | * |
| 5756 | * @param subId the subscription ID that this request applies to. |
| 5757 | * @return PRLVersion or null if error. |
| 5758 | */ |
| 5759 | @Override |
| 5760 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5761 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5762 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5763 | |
| 5764 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5765 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | if (phone == null) { |
| 5767 | return null; |
| 5768 | } |
| 5769 | String cdmaPrlVersion = null; |
| 5770 | try { |
| 5771 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5772 | } catch (Exception e) { |
| 5773 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5774 | } |
| 5775 | return cdmaPrlVersion; |
| 5776 | } finally { |
| 5777 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5778 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5782 | * Get snapshot of Telephony histograms |
| 5783 | * @return List of Telephony histograms |
| 5784 | * @hide |
| 5785 | */ |
| 5786 | @Override |
| 5787 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5788 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5789 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5790 | |
| 5791 | final long identity = Binder.clearCallingIdentity(); |
| 5792 | try { |
| 5793 | return RIL.getTelephonyRILTimingHistograms(); |
| 5794 | } finally { |
| 5795 | Binder.restoreCallingIdentity(identity); |
| 5796 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5797 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5798 | |
| 5799 | /** |
| 5800 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5801 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5802 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5803 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5804 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5805 | * @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] | 5806 | */ |
| 5807 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5808 | @TelephonyManager.SetCarrierRestrictionResult |
| 5809 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5810 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5811 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5812 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5813 | if (carrierRestrictionRules == null) { |
| 5814 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5815 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5816 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5817 | final long identity = Binder.clearCallingIdentity(); |
| 5818 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5819 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5820 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5821 | } finally { |
| 5822 | Binder.restoreCallingIdentity(identity); |
| 5823 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | /** |
| 5827 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5828 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5829 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5830 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5831 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5832 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5833 | */ |
| 5834 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5835 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5836 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5837 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5838 | |
| 5839 | final long identity = Binder.clearCallingIdentity(); |
| 5840 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5841 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5842 | if (response instanceof CarrierRestrictionRules) { |
| 5843 | return (CarrierRestrictionRules) response; |
| 5844 | } |
| 5845 | // Response is an Exception of some kind, |
| 5846 | // which is signalled to the user as a NULL retval |
| 5847 | return null; |
| 5848 | } catch (Exception e) { |
| 5849 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5850 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5851 | } finally { |
| 5852 | Binder.restoreCallingIdentity(identity); |
| 5853 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5854 | } |
| 5855 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5856 | /** |
| 5857 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5858 | * @param subId the subscription ID that this action applies to. |
| 5859 | * @param enabled control enable or disable metered apns. |
| 5860 | * {@hide} |
| 5861 | */ |
| 5862 | @Override |
| 5863 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5864 | enforceModifyPermission(); |
| 5865 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5866 | |
| 5867 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5868 | if (phone == null) { |
| 5869 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5870 | return; |
| 5871 | } |
| 5872 | try { |
| 5873 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5874 | } catch (Exception e) { |
| 5875 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5876 | } finally { |
| 5877 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5878 | } |
| 5879 | } |
| 5880 | |
| 5881 | /** |
| 5882 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5883 | * @param subId the subscription ID that this action applies to. |
| 5884 | * @param enabled control enable or disable radio. |
| 5885 | * {@hide} |
| 5886 | */ |
| 5887 | @Override |
| 5888 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5889 | enforceModifyPermission(); |
| 5890 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5891 | |
| 5892 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5893 | if (phone == null) { |
| 5894 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5895 | return; |
| 5896 | } |
| 5897 | try { |
| 5898 | phone.carrierActionSetRadioEnabled(enabled); |
| 5899 | } catch (Exception e) { |
| 5900 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5901 | } finally { |
| 5902 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5903 | } |
| 5904 | } |
| 5905 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5906 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5907 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5908 | * network status based on which carrier apps could apply actions accordingly, |
| 5909 | * enable/disable default url handler for example. |
| 5910 | * |
| 5911 | * @param subId the subscription ID that this action applies to. |
| 5912 | * @param report control start/stop reporting the default network status. |
| 5913 | * {@hide} |
| 5914 | */ |
| 5915 | @Override |
| 5916 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5917 | enforceModifyPermission(); |
| 5918 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5919 | |
| 5920 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5921 | if (phone == null) { |
| 5922 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5923 | return; |
| 5924 | } |
| 5925 | try { |
| 5926 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5927 | } catch (Exception e) { |
| 5928 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | } finally { |
| 5930 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 5935 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 5936 | * @param subId the subscription ID that this action applies to. |
| 5937 | * {@hide} |
| 5938 | */ |
| 5939 | @Override |
| 5940 | public void carrierActionResetAll(int subId) { |
| 5941 | enforceModifyPermission(); |
| 5942 | final Phone phone = getPhone(subId); |
| 5943 | if (phone == null) { |
| 5944 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 5945 | return; |
| 5946 | } |
| 5947 | try { |
| 5948 | phone.carrierActionResetAll(); |
| 5949 | } catch (Exception e) { |
| 5950 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 5951 | } |
| 5952 | } |
| 5953 | |
| 5954 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5955 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5956 | * bug report is being generated. |
| 5957 | */ |
| 5958 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5959 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5960 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5961 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5962 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5963 | + Binder.getCallingPid() |
| 5964 | + ", uid=" + Binder.getCallingUid() |
| 5965 | + "without permission " |
| 5966 | + android.Manifest.permission.DUMP); |
| 5967 | return; |
| 5968 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5969 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5970 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5971 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5972 | @Override |
| 5973 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5974 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5975 | throws RemoteException { |
| 5976 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5977 | } |
| 5978 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5979 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5980 | * Get aggregated video call data usage since boot. |
| 5981 | * |
| 5982 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5983 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5984 | * {@hide} |
| 5985 | */ |
| 5986 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5987 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5988 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5989 | null); |
| 5990 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | final long identity = Binder.clearCallingIdentity(); |
| 5992 | try { |
| 5993 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5994 | // records the delta with the corresponding network identity. |
| 5995 | // We just return the total video call data usage snapshot since boot. |
| 5996 | Phone phone = getPhone(subId); |
| 5997 | if (phone != null) { |
| 5998 | return phone.getVtDataUsage(perUidStats); |
| 5999 | } |
| 6000 | return null; |
| 6001 | } finally { |
| 6002 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6003 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6004 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6005 | |
| 6006 | /** |
| 6007 | * Policy control of data connection. Usually used when data limit is passed. |
| 6008 | * @param enabled True if enabling the data, otherwise disabling. |
| 6009 | * @param subId Subscription index |
| 6010 | * {@hide} |
| 6011 | */ |
| 6012 | @Override |
| 6013 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6014 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6015 | |
| 6016 | final long identity = Binder.clearCallingIdentity(); |
| 6017 | try { |
| 6018 | Phone phone = getPhone(subId); |
| 6019 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6020 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6021 | } |
| 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6024 | } |
| 6025 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6026 | |
| 6027 | /** |
| 6028 | * Get Client request stats |
| 6029 | * @return List of Client Request Stats |
| 6030 | * @hide |
| 6031 | */ |
| 6032 | @Override |
| 6033 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6034 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6035 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6036 | return null; |
| 6037 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6038 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6039 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6040 | final long identity = Binder.clearCallingIdentity(); |
| 6041 | try { |
| 6042 | if (phone != null) { |
| 6043 | return phone.getClientRequestStats(); |
| 6044 | } |
| 6045 | |
| 6046 | return null; |
| 6047 | } finally { |
| 6048 | Binder.restoreCallingIdentity(identity); |
| 6049 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6050 | } |
| 6051 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6052 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6053 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6054 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6055 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6056 | |
| 6057 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6058 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6059 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6060 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6061 | * @param state State of SIM (power down, power up, pass through) |
| 6062 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6063 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6064 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6065 | * |
| 6066 | **/ |
| 6067 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6068 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6069 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6070 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6071 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6072 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6073 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6074 | final long identity = Binder.clearCallingIdentity(); |
| 6075 | try { |
| 6076 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6077 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6078 | } |
| 6079 | } finally { |
| 6080 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6081 | } |
| 6082 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6083 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6084 | private boolean isUssdApiAllowed(int subId) { |
| 6085 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6086 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6087 | if (configManager == null) { |
| 6088 | return false; |
| 6089 | } |
| 6090 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6091 | if (pb == null) { |
| 6092 | return false; |
| 6093 | } |
| 6094 | return pb.getBoolean( |
| 6095 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6096 | } |
| 6097 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6098 | /** |
| 6099 | * Check if phone is in emergency callback mode |
| 6100 | * @return true if phone is in emergency callback mode |
| 6101 | * @param subId sub id |
| 6102 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6103 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6104 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6105 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6106 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | |
| 6108 | final long identity = Binder.clearCallingIdentity(); |
| 6109 | try { |
| 6110 | if (phone != null) { |
| 6111 | return phone.isInEcm(); |
| 6112 | } else { |
| 6113 | return false; |
| 6114 | } |
| 6115 | } finally { |
| 6116 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6117 | } |
| 6118 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6119 | |
| 6120 | /** |
| 6121 | * Get the current signal strength information for the given subscription. |
| 6122 | * Because this information is not updated when the device is in a low power state |
| 6123 | * it should not be relied-upon to be current. |
| 6124 | * @param subId Subscription index |
| 6125 | * @return the most recent cached signal strength info from the modem |
| 6126 | */ |
| 6127 | @Override |
| 6128 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | final long identity = Binder.clearCallingIdentity(); |
| 6130 | try { |
| 6131 | Phone p = getPhone(subId); |
| 6132 | if (p == null) { |
| 6133 | return null; |
| 6134 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6135 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6136 | return p.getSignalStrength(); |
| 6137 | } finally { |
| 6138 | Binder.restoreCallingIdentity(identity); |
| 6139 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6140 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6141 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6142 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6143 | * Get the current modem radio state for the given slot. |
| 6144 | * @param slotIndex slot index. |
| 6145 | * @param callingPackage the name of the package making the call. |
| 6146 | * @return the current radio power state from the modem |
| 6147 | */ |
| 6148 | @Override |
| 6149 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6150 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6151 | if (phone != null) { |
| 6152 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6153 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6154 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6155 | } |
| 6156 | |
| 6157 | final long identity = Binder.clearCallingIdentity(); |
| 6158 | try { |
| 6159 | return phone.getRadioPowerState(); |
| 6160 | } finally { |
| 6161 | Binder.restoreCallingIdentity(identity); |
| 6162 | } |
| 6163 | } |
| 6164 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6165 | } |
| 6166 | |
| 6167 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6168 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6169 | * |
| 6170 | * <p>Requires one of the following permissions: |
| 6171 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6172 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6173 | * privileges. |
| 6174 | * |
| 6175 | * @param subId subscription id |
| 6176 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6177 | * {@code false}. |
| 6178 | */ |
| 6179 | @Override |
| 6180 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6181 | boolean isEnabled = false; |
| 6182 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6183 | try { |
| 6184 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6185 | null /* message */); |
| 6186 | Phone phone = getPhone(subId); |
| 6187 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6188 | } catch (Exception e) { |
| 6189 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6190 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6191 | } finally { |
| 6192 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6193 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6194 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6195 | } |
| 6196 | |
| 6197 | |
| 6198 | /** |
| 6199 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6200 | * |
| 6201 | * <p> Requires permission: |
| 6202 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6203 | * privileges. |
| 6204 | * |
| 6205 | * @param subId subscription id |
| 6206 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6207 | */ |
| 6208 | @Override |
| 6209 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6210 | final long identity = Binder.clearCallingIdentity(); |
| 6211 | try { |
| 6212 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6213 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6214 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6215 | Phone phone = getPhone(subId); |
| 6216 | if (phone != null) { |
| 6217 | phone.setDataRoamingEnabled(isEnabled); |
| 6218 | } |
| 6219 | } finally { |
| 6220 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6221 | } |
| 6222 | } |
| 6223 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6224 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6225 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 6226 | boolean isAllowed = true; |
| 6227 | final long identity = Binder.clearCallingIdentity(); |
| 6228 | try { |
| 6229 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6230 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6231 | Phone phone = getPhone(subId); |
| 6232 | if (phone != null) { |
| 6233 | isAllowed = phone.isCspPlmnEnabled(); |
| 6234 | } |
| 6235 | } finally { |
| 6236 | Binder.restoreCallingIdentity(identity); |
| 6237 | } |
| 6238 | return isAllowed; |
| 6239 | } |
| 6240 | |
| 6241 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6242 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6243 | try { |
| 6244 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 6245 | } catch (SecurityException e) { |
| 6246 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6247 | // has carrier privileges on an active UICC |
| 6248 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6249 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6250 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); |
| 6251 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6252 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6253 | |
| 6254 | final long identity = Binder.clearCallingIdentity(); |
| 6255 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6256 | UiccController uiccController = UiccController.getInstance(); |
| 6257 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 6258 | |
| 6259 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 6260 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 6261 | // Remove private info if the caller doesn't have access |
| 6262 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6263 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6264 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 6265 | UiccProfile profile = card.getUiccProfile(); |
| 6266 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6267 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6268 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6269 | } else { |
| 6270 | filteredInfos.add(cardInfo); |
| 6271 | } |
| 6272 | } |
| 6273 | return filteredInfos; |
| 6274 | } |
| 6275 | return cardInfos; |
| 6276 | } catch (PackageManager.NameNotFoundException e) { |
| 6277 | // This should not happen since we pass the package info in from TelephonyManager |
| 6278 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6279 | } finally { |
| 6280 | Binder.restoreCallingIdentity(identity); |
| 6281 | } |
| 6282 | } |
| 6283 | |
| 6284 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6285 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6286 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6287 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6288 | final long identity = Binder.clearCallingIdentity(); |
| 6289 | try { |
| 6290 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6291 | if (slots == null) { |
| 6292 | Rlog.i(LOG_TAG, "slots is null."); |
| 6293 | return null; |
| 6294 | } |
| 6295 | |
| 6296 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6297 | for (int i = 0; i < slots.length; i++) { |
| 6298 | UiccSlot slot = slots[i]; |
| 6299 | if (slot == null) { |
| 6300 | continue; |
| 6301 | } |
| 6302 | |
| 6303 | String cardId; |
| 6304 | UiccCard card = slot.getUiccCard(); |
| 6305 | if (card != null) { |
| 6306 | cardId = card.getCardId(); |
| 6307 | } else { |
| 6308 | cardId = slot.getIccId(); |
| 6309 | } |
| 6310 | |
| 6311 | int cardState = 0; |
| 6312 | switch (slot.getCardState()) { |
| 6313 | case CARDSTATE_ABSENT: |
| 6314 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6315 | break; |
| 6316 | case CARDSTATE_PRESENT: |
| 6317 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6318 | break; |
| 6319 | case CARDSTATE_ERROR: |
| 6320 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6321 | break; |
| 6322 | case CARDSTATE_RESTRICTED: |
| 6323 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6324 | break; |
| 6325 | default: |
| 6326 | break; |
| 6327 | |
| 6328 | } |
| 6329 | |
| 6330 | infos[i] = new UiccSlotInfo( |
| 6331 | slot.isActive(), |
| 6332 | slot.isEuicc(), |
| 6333 | cardId, |
| 6334 | cardState, |
| 6335 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6336 | slot.isExtendedApduSupported(), |
| 6337 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6338 | } |
| 6339 | return infos; |
| 6340 | } finally { |
| 6341 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6342 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | @Override |
| 6346 | public boolean switchSlots(int[] physicalSlots) { |
| 6347 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6348 | |
| 6349 | final long identity = Binder.clearCallingIdentity(); |
| 6350 | try { |
| 6351 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6352 | } finally { |
| 6353 | Binder.restoreCallingIdentity(identity); |
| 6354 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6355 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6356 | |
| 6357 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6358 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6359 | final long identity = Binder.clearCallingIdentity(); |
| 6360 | try { |
| 6361 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6362 | } finally { |
| 6363 | Binder.restoreCallingIdentity(identity); |
| 6364 | } |
| 6365 | } |
| 6366 | |
| 6367 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6368 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6369 | enforceModifyPermission(); |
| 6370 | final Phone phone = getPhone(subId); |
| 6371 | if (phone == null) { |
| 6372 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6373 | return; |
| 6374 | } |
| 6375 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6376 | final long identity = Binder.clearCallingIdentity(); |
| 6377 | try { |
| 6378 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6379 | } finally { |
| 6380 | Binder.restoreCallingIdentity(identity); |
| 6381 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6382 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6383 | |
| 6384 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6385 | * A test API to reload the UICC profile. |
| 6386 | * |
| 6387 | * <p>Requires that the calling app has permission |
| 6388 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6389 | * @hide |
| 6390 | */ |
| 6391 | @Override |
| 6392 | public void refreshUiccProfile(int subId) { |
| 6393 | enforceModifyPermission(); |
| 6394 | |
| 6395 | final long identity = Binder.clearCallingIdentity(); |
| 6396 | try { |
| 6397 | Phone phone = getPhone(subId); |
| 6398 | if (phone == null) { |
| 6399 | return; |
| 6400 | } |
| 6401 | UiccCard uiccCard = phone.getUiccCard(); |
| 6402 | if (uiccCard == null) { |
| 6403 | return; |
| 6404 | } |
| 6405 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6406 | if (uiccProfile == null) { |
| 6407 | return; |
| 6408 | } |
| 6409 | uiccProfile.refresh(); |
| 6410 | } finally { |
| 6411 | Binder.restoreCallingIdentity(identity); |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6416 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6417 | */ |
| 6418 | private boolean getDefaultDataEnabled() { |
| 6419 | return "true".equalsIgnoreCase( |
| 6420 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6421 | } |
| 6422 | |
| 6423 | /** |
| 6424 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6425 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6426 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6427 | */ |
| 6428 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6429 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6430 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6431 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6432 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6433 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6434 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6435 | return isDataRoamingEnabled; |
| 6436 | } |
| 6437 | |
| 6438 | /** |
| 6439 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6440 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6441 | */ |
| 6442 | private int getDefaultNetworkType(int subId) { |
| 6443 | return Integer.parseInt( |
| 6444 | TelephonyManager.getTelephonyProperty( |
| 6445 | mSubscriptionController.getPhoneId(subId), |
| 6446 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6447 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6448 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6449 | |
| 6450 | @Override |
| 6451 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6452 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6453 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6454 | |
| 6455 | final long identity = Binder.clearCallingIdentity(); |
| 6456 | try { |
| 6457 | final Phone phone = getPhone(subId); |
| 6458 | if (phone == null) { |
| 6459 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6460 | return; |
| 6461 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 6462 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 6463 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6464 | } finally { |
| 6465 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6466 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6467 | } |
| 6468 | |
| 6469 | @Override |
| 6470 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6471 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6472 | |
| 6473 | final long identity = Binder.clearCallingIdentity(); |
| 6474 | try { |
| 6475 | final Phone phone = getPhone(subId); |
| 6476 | if (phone == null) { |
| 6477 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6478 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6479 | } |
| 6480 | return phone.getCarrierIdListVersion(); |
| 6481 | } finally { |
| 6482 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6483 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6484 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6485 | |
| 6486 | @Override |
| 6487 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6488 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6489 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6490 | return -1; |
| 6491 | } |
| 6492 | |
| 6493 | final long identity = Binder.clearCallingIdentity(); |
| 6494 | try { |
| 6495 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6496 | } finally { |
| 6497 | Binder.restoreCallingIdentity(identity); |
| 6498 | } |
| 6499 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6500 | |
| 6501 | @Override |
| 6502 | public int getCdmaRoamingMode(int subId) { |
| 6503 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6504 | mApp, subId, "getCdmaRoamingMode"); |
| 6505 | |
| 6506 | final long identity = Binder.clearCallingIdentity(); |
| 6507 | try { |
| 6508 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6509 | } finally { |
| 6510 | Binder.restoreCallingIdentity(identity); |
| 6511 | } |
| 6512 | } |
| 6513 | |
| 6514 | @Override |
| 6515 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6516 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6517 | mApp, subId, "setCdmaRoamingMode"); |
| 6518 | |
| 6519 | final long identity = Binder.clearCallingIdentity(); |
| 6520 | try { |
| 6521 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6522 | } finally { |
| 6523 | Binder.restoreCallingIdentity(identity); |
| 6524 | } |
| 6525 | } |
| 6526 | |
| 6527 | @Override |
| 6528 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6529 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6530 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6531 | |
| 6532 | final long identity = Binder.clearCallingIdentity(); |
| 6533 | try { |
| 6534 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6535 | } finally { |
| 6536 | Binder.restoreCallingIdentity(identity); |
| 6537 | } |
| 6538 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 6539 | |
| 6540 | private void ensureUserRunning(int userId) { |
| 6541 | if (!mUserManager.isUserRunning(userId)) { |
| 6542 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | /** |
| 6547 | * Returns a list of SMS apps on a given user. |
| 6548 | * |
| 6549 | * Only the shell user (UID 2000 or 0) can call it. |
| 6550 | * Target user must be running. |
| 6551 | */ |
| 6552 | @Override |
| 6553 | public String[] getSmsApps(int userId) { |
| 6554 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6555 | ensureUserRunning(userId); |
| 6556 | |
| 6557 | final Collection<SmsApplicationData> apps = |
| 6558 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6559 | |
| 6560 | String[] ret = new String[apps.size()]; |
| 6561 | int i = 0; |
| 6562 | for (SmsApplicationData app : apps) { |
| 6563 | ret[i++] = app.mPackageName; |
| 6564 | } |
| 6565 | return ret; |
| 6566 | } |
| 6567 | |
| 6568 | /** |
| 6569 | * Returns the default SMS app package name on a given user. |
| 6570 | * |
| 6571 | * Only the shell user (UID 2000 or 0) can call it. |
| 6572 | * Target user must be running. |
| 6573 | */ |
| 6574 | @Override |
| 6575 | public String getDefaultSmsApp(int userId) { |
| 6576 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6577 | ensureUserRunning(userId); |
| 6578 | |
| 6579 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6580 | /* updateIfNeeded= */ true, userId); |
| 6581 | return cn == null ? null : cn.getPackageName(); |
| 6582 | } |
| 6583 | |
| 6584 | /** |
| 6585 | * Set a package as the default SMS app on a given user. |
| 6586 | * |
| 6587 | * Only the shell user (UID 2000 or 0) can call it. |
| 6588 | * Target user must be running. |
| 6589 | */ |
| 6590 | @Override |
| 6591 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6592 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6593 | ensureUserRunning(userId); |
| 6594 | |
| 6595 | boolean found = false; |
| 6596 | for (String pkg : getSmsApps(userId)) { |
| 6597 | if (TextUtils.equals(packageName, pkg)) { |
| 6598 | found = true; |
| 6599 | break; |
| 6600 | } |
| 6601 | } |
| 6602 | if (!found) { |
| 6603 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6604 | } |
| 6605 | |
| 6606 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6607 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6608 | |
| 6609 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6610 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6611 | String callingPackage) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6612 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6613 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6614 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6615 | } |
| 6616 | final long identity = Binder.clearCallingIdentity(); |
| 6617 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6618 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6619 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6620 | if (phone.getEmergencyNumberTracker() != null |
| 6621 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6622 | emergencyNumberListInternal.put( |
| 6623 | phone.getSubId(), |
| 6624 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6625 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6626 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6627 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6628 | } finally { |
| 6629 | Binder.restoreCallingIdentity(identity); |
| 6630 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 6631 | } |
| 6632 | |
| 6633 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6634 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6635 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6636 | if (!exactMatch) { |
| 6637 | TelephonyPermissions |
| 6638 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 6639 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6640 | } |
| 6641 | final long identity = Binder.clearCallingIdentity(); |
| 6642 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6643 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6644 | if (phone.getEmergencyNumberTracker() != null |
| 6645 | && phone.getEmergencyNumberTracker() != null) { |
| 6646 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6647 | number, exactMatch)) { |
| 6648 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6649 | } |
| 6650 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6651 | } |
| 6652 | return false; |
| 6653 | } finally { |
| 6654 | Binder.restoreCallingIdentity(identity); |
| 6655 | } |
| 6656 | } |
| 6657 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6658 | /** |
| 6659 | * Update emergency number list for test mode. |
| 6660 | */ |
| 6661 | @Override |
| 6662 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6663 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6664 | "updateEmergencyNumberListTestMode"); |
| 6665 | |
| 6666 | final long identity = Binder.clearCallingIdentity(); |
| 6667 | try { |
| 6668 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6669 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6670 | if (tracker != null) { |
| 6671 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6672 | } |
| 6673 | } |
| 6674 | } finally { |
| 6675 | Binder.restoreCallingIdentity(identity); |
| 6676 | } |
| 6677 | } |
| 6678 | |
| 6679 | /** |
| 6680 | * Get the full emergency number list for test mode. |
| 6681 | */ |
| 6682 | @Override |
| 6683 | public List<String> getEmergencyNumberListTestMode() { |
| 6684 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6685 | "getEmergencyNumberListTestMode"); |
| 6686 | |
| 6687 | final long identity = Binder.clearCallingIdentity(); |
| 6688 | try { |
| 6689 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6690 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6691 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6692 | if (tracker != null) { |
| 6693 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6694 | emergencyNumbers.add(num.getNumber()); |
| 6695 | } |
| 6696 | } |
| 6697 | } |
| 6698 | return new ArrayList<>(emergencyNumbers); |
| 6699 | } finally { |
| 6700 | Binder.restoreCallingIdentity(identity); |
| 6701 | } |
| 6702 | } |
| 6703 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6704 | @Override |
| 6705 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6706 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6707 | Phone phone = getPhone(subId); |
| 6708 | if (phone == null) { |
| 6709 | return null; |
| 6710 | } |
| 6711 | final long identity = Binder.clearCallingIdentity(); |
| 6712 | try { |
| 6713 | UiccProfile profile = UiccController.getInstance() |
| 6714 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6715 | if (profile != null) { |
| 6716 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6717 | } |
| 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(identity); |
| 6720 | } |
| 6721 | return null; |
| 6722 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6723 | |
| 6724 | /** |
| 6725 | * Enable or disable a modem stack. |
| 6726 | */ |
| 6727 | @Override |
| 6728 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6729 | enforceModifyPermission(); |
| 6730 | |
| 6731 | final long identity = Binder.clearCallingIdentity(); |
| 6732 | try { |
| 6733 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6734 | if (phone == null) { |
| 6735 | return false; |
| 6736 | } else { |
| 6737 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6738 | } |
| 6739 | } finally { |
| 6740 | Binder.restoreCallingIdentity(identity); |
| 6741 | } |
| 6742 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6743 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame^] | 6744 | /** |
| 6745 | * Whether a modem stack is enabled or not. |
| 6746 | */ |
| 6747 | @Override |
| 6748 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) { |
| 6749 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6750 | if (phone == null) return false; |
| 6751 | |
| 6752 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6753 | mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) { |
| 6754 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6755 | } |
| 6756 | |
| 6757 | final long identity = Binder.clearCallingIdentity(); |
| 6758 | try { |
| 6759 | return PhoneConfigurationManager.getInstance().getPhoneStatus(phone); |
| 6760 | } finally { |
| 6761 | Binder.restoreCallingIdentity(identity); |
| 6762 | } |
| 6763 | } |
| 6764 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6765 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6766 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6767 | enforceModifyPermission(); |
| 6768 | |
| 6769 | final long identity = Binder.clearCallingIdentity(); |
| 6770 | try { |
| 6771 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6772 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6773 | .commit(); |
| 6774 | } finally { |
| 6775 | Binder.restoreCallingIdentity(identity); |
| 6776 | } |
| 6777 | } |
| 6778 | |
| 6779 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6780 | @TelephonyManager.IsMultiSimSupportedResult |
| 6781 | public int isMultiSimSupported(String callingPackage) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6782 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6783 | getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) { |
| 6784 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6785 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6786 | |
| 6787 | final long identity = Binder.clearCallingIdentity(); |
| 6788 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6789 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6790 | } finally { |
| 6791 | Binder.restoreCallingIdentity(identity); |
| 6792 | } |
| 6793 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6794 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6795 | @TelephonyManager.IsMultiSimSupportedResult |
| 6796 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6797 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6798 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6799 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6800 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 6801 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6802 | } |
| 6803 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6804 | // supported by the modem, indicate that it is restricted. |
| 6805 | PhoneCapability staticCapability = |
| 6806 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6807 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6808 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 6809 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6810 | } |
| 6811 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6812 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 6813 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6814 | } |
| 6815 | // Check if support of multiple SIMs is restricted by carrier |
| 6816 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6817 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6818 | } |
| 6819 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6820 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6821 | } |
| 6822 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6823 | /** |
| 6824 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6825 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6826 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6827 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6828 | * @param numOfSims number of active sims we want to switch to |
| 6829 | */ |
| 6830 | @Override |
| 6831 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6832 | if (numOfSims == 1) { |
| 6833 | enforceModifyPermission(); |
| 6834 | } else { |
| 6835 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6836 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6837 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6838 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6839 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6840 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6841 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 6842 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6843 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6844 | return; |
| 6845 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 6846 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6847 | } finally { |
| 6848 | Binder.restoreCallingIdentity(identity); |
| 6849 | } |
| 6850 | } |
| 6851 | |
| 6852 | /** |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6853 | * Get whether reboot is required or not after making changes to modem configurations. |
Nazanin Bakhshi | 4a68f5f | 2019-02-08 14:31:19 -0800 | [diff] [blame] | 6854 | * Return value defaults to true |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6855 | */ |
| 6856 | @Override |
| 6857 | public boolean isRebootRequiredForModemConfigChange() { |
| 6858 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6859 | final long identity = Binder.clearCallingIdentity(); |
| 6860 | try { |
| 6861 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6862 | } finally { |
| 6863 | Binder.restoreCallingIdentity(identity); |
| 6864 | } |
| 6865 | } |
| 6866 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 6867 | private void updateModemStateMetrics() { |
| 6868 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6869 | // TODO: check the state for each modem if the api is ready. |
| 6870 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6871 | } |
| 6872 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6873 | @Override |
| 6874 | public int[] getSlotsMapping() { |
| 6875 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6876 | |
| 6877 | final long identity = Binder.clearCallingIdentity(); |
| 6878 | try { |
| 6879 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6880 | // All logical slots should have a mapping to a physical slot. |
| 6881 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6882 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6883 | for (int i = 0; i < slotInfos.length; i++) { |
| 6884 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6885 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6886 | } |
| 6887 | } |
| 6888 | return logicalSlotsMapping; |
| 6889 | } finally { |
| 6890 | Binder.restoreCallingIdentity(identity); |
| 6891 | } |
| 6892 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6893 | |
| 6894 | /** |
| 6895 | * Get the IRadio HAL Version |
| 6896 | */ |
| 6897 | @Override |
| 6898 | public int getRadioHalVersion() { |
| 6899 | Phone phone = getDefaultPhone(); |
| 6900 | if (phone == null) return -1; |
| 6901 | HalVersion hv = phone.getHalVersion(); |
| 6902 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 6903 | return hv.major * 100 + hv.minor; |
| 6904 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6905 | } |