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 | 0963c86 | 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 | bcb01bc | 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 | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 90 | import android.telephony.data.ApnSetting; |
calvinpan | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 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 | 4c46071 | 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 | 4c46071 | 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 | 4c46071 | 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 | 0258169 | 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 | f144d94 | 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; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [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 | 9d4df8b | 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 | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.ims.ImsResolver; |
Pengquan Meng | 92d253b | 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; |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 165 | import java.util.Collection; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 166 | import java.util.HashMap; |
sqian | 9d4df8b | 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 | 9d4df8b | 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 | 1cc0abe | 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 | 0c05b50 | 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 | 1cc0abe | 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 | 509b5b7 | 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 | f144d94 | 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 | d3107c5 | 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 | e435a3e | 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 | e435a3e | 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 | e435a3e | 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 | 2f2cc69 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 2f2cc69 | 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 | 0c05b50 | 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 | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 672 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | e435a3e | 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 | 2f2cc69 | 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 | 1cc0abe | 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 | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 692 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | 2f2cc69 | 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 | 1cc0abe | 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 | 0c05b50 | 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 | 2f2cc69 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | dd9ac82 | 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 | 2f2cc69 | 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 | 0c05b50 | 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 | 0963c86 | 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 | 0963c86 | 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 | 0963c86 | 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 | 0c05b50 | 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 | 2f2cc69 | 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 | 0963c86 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | 1cc0abe | 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 | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1097 | defaultPhone.rebootModem(onCompleted); |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1098 | break; |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1099 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1100 | handleNullReturnEvent(msg, "rebootModem"); |
| 1101 | break; |
Malcolm Chen | 509b5b7 | 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 | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1106 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 509b5b7 | 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 | 9b37957 | 2019-03-01 17:27:47 -0800 | [diff] [blame] | 1114 | //update the cache as modem status has changed |
| 1115 | mPhoneConfigurationManager.addToPhoneStatusCache( |
| 1116 | request.phone.getPhoneId(), msg.arg1 == 1); |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 1117 | updateModemStateMetrics(); |
Malcolm Chen | 509b5b7 | 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 | 0c05b50 | 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 | 0c05b50 | 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 | e435a3e | 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 | e435a3e | 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 | 2f2cc69 | 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 | 2f2cc69 | 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 | 2f2cc69 | 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(); |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1284 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | 2f2cc69 | 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 | f144d94 | 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 | 2f2cc69 | 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 | 73b078d | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1736 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1756 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | 311536f | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1772 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | 2f2cc69 | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | 2f2cc69 | 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 | 2f2cc69 | 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 | d965c8b | 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 | d965c8b | 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 | 2f2cc69 | 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 | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2111 | |
| 2112 | final long identity = Binder.clearCallingIdentity(); |
| 2113 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2114 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | d965c8b | 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(); |
| 2127 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2128 | mApp, subId, callingPackage, "getImeiForSlot")) { |
| 2129 | return null; |
| 2130 | } |
Malcolm Chen | d965c8b | 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 | 2f2cc69 | 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(); |
| 2159 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 2160 | mApp, subId, callingPackage, "getMeidForSlot")) { |
| 2161 | return null; |
| 2162 | } |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | eed9ae8 | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2225 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2226 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | c93cc28 | 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 | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2231 | : phone.getSpecificCarrierId(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2232 | } finally { |
| 2233 | Binder.restoreCallingIdentity(identity); |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | @Override |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2238 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | c93cc28 | 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 | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2242 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | c93cc28 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2243 | } finally { |
| 2244 | Binder.restoreCallingIdentity(identity); |
| 2245 | } |
| 2246 | } |
| 2247 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2248 | @Override |
chen xu | 4ca4e69 | 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 | 0258169 | 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 | 2f2cc69 | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2429 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2430 | return phone.getLine1Number(); |
| 2431 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2432 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2489 | final long identity = Binder.clearCallingIdentity(); |
| 2490 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2491 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | 2f2cc69 | 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 | d965c8b | 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 | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2528 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | 2f2cc69 | 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 | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2554 | |
| 2555 | final long identity = Binder.clearCallingIdentity(); |
| 2556 | try { |
| 2557 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2558 | mApp, callingPackage, subId, settings); |
Malcolm Chen | d965c8b | 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 | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2567 | |
| 2568 | final long identity = Binder.clearCallingIdentity(); |
| 2569 | try { |
| 2570 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2571 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 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 | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2581 | |
| 2582 | final long identity = Binder.clearCallingIdentity(); |
| 2583 | try { |
| 2584 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2585 | mApp, callingPackage, subId); |
Malcolm Chen | d965c8b | 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 | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2593 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2594 | |
| 2595 | final long identity = Binder.clearCallingIdentity(); |
| 2596 | try { |
| 2597 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2598 | mApp, subId); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2673 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2693 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | d965c8b | 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 | 2f2cc69 | 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 | 2f2cc69 | 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 | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | |
| 2761 | final long identity = Binder.clearCallingIdentity(); |
| 2762 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2763 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | d965c8b | 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 | d965c8b | 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 | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2790 | @Override |
| 2791 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2792 | if (!isActiveSubscription(subId)) { |
| 2793 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2794 | } |
| 2795 | |
Pengquan Meng | 0c05b50 | 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 | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2799 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2800 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2801 | throws RemoteException { |
| 2802 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2803 | final long token = Binder.clearCallingIdentity(); |
| 2804 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2805 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2806 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2807 | .addRegistrationCallbackForSubscription(c, subId); |
| 2808 | } finally { |
| 2809 | Binder.restoreCallingIdentity(token); |
| 2810 | } |
| 2811 | } |
| 2812 | |
| 2813 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2814 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2815 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2816 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2817 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2818 | } |
| 2819 | Binder.withCleanCallingIdentity(() -> { |
| 2820 | try { |
| 2821 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2822 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2823 | .removeRegistrationCallbackForSubscription(c, subId); |
| 2824 | } catch (IllegalArgumentException e) { |
| 2825 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 2826 | + "is inactive, ignoring unregister."); |
| 2827 | // If the subscription is no longer active, just return, since the callback |
| 2828 | // will already have been removed internally. |
| 2829 | } |
| 2830 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2834 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 2835 | throws RemoteException { |
| 2836 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2837 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2838 | final long token = Binder.clearCallingIdentity(); |
| 2839 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2840 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2841 | .addCapabilitiesCallbackForSubscription(c, subId); |
| 2842 | } finally { |
| 2843 | Binder.restoreCallingIdentity(token); |
| 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2848 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 2849 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2850 | |
| 2851 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2852 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2853 | } |
| 2854 | Binder.withCleanCallingIdentity(() -> { |
| 2855 | try { |
| 2856 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2857 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2858 | .removeCapabilitiesCallbackForSubscription(c, subId); |
| 2859 | } catch (IllegalArgumentException e) { |
| 2860 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 2861 | + "is inactive, ignoring unregister."); |
| 2862 | // If the subscription is no longer active, just return, since the callback |
| 2863 | // will already have been removed internally. |
| 2864 | } |
| 2865 | }); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2869 | public boolean isCapable(int subId, int capability, int regTech) { |
| 2870 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2871 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2872 | final long token = Binder.clearCallingIdentity(); |
| 2873 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2874 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2875 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
| 2876 | } catch (ImsException e) { |
| 2877 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 2878 | return false; |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 2879 | } catch (IllegalArgumentException e) { |
| 2880 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 2881 | return false; |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2882 | } finally { |
| 2883 | Binder.restoreCallingIdentity(token); |
| 2884 | } |
| 2885 | } |
| 2886 | |
| 2887 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2888 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 2889 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2890 | final long token = Binder.clearCallingIdentity(); |
| 2891 | try { |
| 2892 | Phone phone = getPhone(subId); |
| 2893 | if (phone == null) return false; |
| 2894 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 2895 | } finally { |
| 2896 | Binder.restoreCallingIdentity(token); |
| 2897 | } |
| 2898 | } |
| 2899 | |
| 2900 | @Override |
| 2901 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 2902 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 2903 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 2904 | final long token = Binder.clearCallingIdentity(); |
| 2905 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2906 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2907 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
| 2908 | } finally { |
| 2909 | Binder.restoreCallingIdentity(token); |
| 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2914 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2915 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2916 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2917 | final long identity = Binder.clearCallingIdentity(); |
| 2918 | try { |
| 2919 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2920 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2921 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
| 2922 | } finally { |
| 2923 | Binder.restoreCallingIdentity(identity); |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2928 | public boolean isVtSettingEnabled(int subId) { |
| 2929 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2930 | final long identity = Binder.clearCallingIdentity(); |
| 2931 | try { |
| 2932 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2933 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2934 | getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 2935 | } finally { |
| 2936 | Binder.restoreCallingIdentity(identity); |
| 2937 | } |
| 2938 | } |
| 2939 | |
| 2940 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2941 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2943 | "setVtSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2944 | final long identity = Binder.clearCallingIdentity(); |
| 2945 | try { |
| 2946 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2947 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2948 | } finally { |
| 2949 | Binder.restoreCallingIdentity(identity); |
| 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | @Override |
| 2954 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 2955 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
| 2958 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2959 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2960 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
| 2961 | } finally { |
| 2962 | Binder.restoreCallingIdentity(identity); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2967 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2969 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2970 | final long identity = Binder.clearCallingIdentity(); |
| 2971 | try { |
| 2972 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2973 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2974 | } finally { |
| 2975 | Binder.restoreCallingIdentity(identity); |
| 2976 | } |
| 2977 | } |
| 2978 | |
| 2979 | @Override |
| 2980 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 2981 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 2982 | final long identity = Binder.clearCallingIdentity(); |
| 2983 | try { |
| 2984 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2985 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2986 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
| 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | @Override |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2993 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 0de268e | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 2995 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2996 | final long identity = Binder.clearCallingIdentity(); |
| 2997 | try { |
| 2998 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2999 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3000 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
| 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(identity); |
| 3003 | } |
| 3004 | } |
| 3005 | |
| 3006 | @Override |
| 3007 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3008 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3009 | "setVoWiFiNonPersistent"); |
| 3010 | final long identity = Binder.clearCallingIdentity(); |
| 3011 | try { |
| 3012 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3013 | boolean isRoaming = TelephonyManager.from( |
| 3014 | getPhone(subId).getContext()).isNetworkRoaming(subId); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3015 | ImsManager.getInstance(mApp, |
Brad Ebinger | 43e66f1 | 2019-01-15 12:40:04 -0800 | [diff] [blame] | 3016 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(identity); |
| 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | @Override |
| 3023 | public int getVoWiFiModeSetting(int subId) { |
| 3024 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3025 | final long identity = Binder.clearCallingIdentity(); |
| 3026 | try { |
| 3027 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3028 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3029 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
| 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | @Override |
| 3036 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3038 | "setVoWiFiModeSetting"); |
| 3039 | final long identity = Binder.clearCallingIdentity(); |
| 3040 | try { |
| 3041 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3042 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3043 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
| 3044 | } finally { |
| 3045 | Binder.restoreCallingIdentity(identity); |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | @Override |
| 3050 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3051 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
| 3054 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3055 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3056 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
| 3057 | } finally { |
| 3058 | Binder.restoreCallingIdentity(identity); |
| 3059 | } |
| 3060 | } |
| 3061 | |
| 3062 | @Override |
| 3063 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3064 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3065 | "setVoWiFiRoamingModeSetting"); |
| 3066 | final long identity = Binder.clearCallingIdentity(); |
| 3067 | try { |
| 3068 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3069 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3070 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
| 3071 | } finally { |
| 3072 | Binder.restoreCallingIdentity(identity); |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | @Override |
| 3077 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3078 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3079 | "setRttCapabilityEnabled"); |
| 3080 | final long identity = Binder.clearCallingIdentity(); |
| 3081 | try { |
| 3082 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3083 | ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3084 | getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3085 | } finally { |
| 3086 | Binder.restoreCallingIdentity(identity); |
| 3087 | } |
| 3088 | } |
| 3089 | |
| 3090 | @Override |
| 3091 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3092 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3093 | final long identity = Binder.clearCallingIdentity(); |
| 3094 | try { |
| 3095 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3096 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3097 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
| 3098 | } finally { |
| 3099 | Binder.restoreCallingIdentity(identity); |
| 3100 | } |
| 3101 | } |
| 3102 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3103 | @Override |
| 3104 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3105 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3106 | final long identity = Binder.clearCallingIdentity(); |
| 3107 | try { |
| 3108 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3109 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3110 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3111 | } finally { |
| 3112 | Binder.restoreCallingIdentity(identity); |
| 3113 | } |
| 3114 | } |
| 3115 | |
| 3116 | @Override |
| 3117 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3118 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3119 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3120 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3121 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3122 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3123 | try { |
| 3124 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | 2f2cc69 | 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 | .removeProvisioningCallbackForSubscription(callback, subId); |
| 3127 | } catch (IllegalArgumentException e) { |
| 3128 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3129 | + "is inactive, ignoring unregister."); |
| 3130 | // If the subscription is no longer active, just return, since the callback will already |
| 3131 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3138 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3139 | boolean isProvisioned) { |
| 3140 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3141 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3142 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3143 | } |
| 3144 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3145 | "setProvisioningStatusForCapability"); |
| 3146 | final long identity = Binder.clearCallingIdentity(); |
| 3147 | try { |
| 3148 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3149 | Phone phone = getPhone(subId); |
| 3150 | if (phone == null) { |
| 3151 | loge("setImsProvisioningStatusForCapability: phone instance null for subid " |
| 3152 | + subId); |
| 3153 | return; |
| 3154 | } |
| 3155 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3156 | return; |
| 3157 | } |
| 3158 | |
| 3159 | // this capability requires provisioning, route to the correct API. |
| 3160 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3161 | switch (capability) { |
| 3162 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3163 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3164 | ims.setVolteProvisioned(isProvisioned); |
| 3165 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3166 | ims.setWfcProvisioned(isProvisioned); |
| 3167 | } |
| 3168 | break; |
| 3169 | } |
| 3170 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3171 | // There is currently no difference in VT provisioning type. |
| 3172 | ims.setVtProvisioned(isProvisioned); |
| 3173 | break; |
| 3174 | } |
| 3175 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3176 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3177 | // change the capability of the feature instead if needed. |
| 3178 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3179 | == isProvisioned) { |
| 3180 | // No change in provisioning. |
| 3181 | return; |
| 3182 | } |
| 3183 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3184 | try { |
| 3185 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
| 3186 | } catch (ImsException e) { |
| 3187 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3188 | + ", Exception" + e.getMessage()); |
| 3189 | } |
| 3190 | break; |
| 3191 | } |
| 3192 | default: { |
| 3193 | throw new IllegalArgumentException("Tried to set provisioning for capability '" |
| 3194 | + capability + "', which does not require provisioning."); |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | } finally { |
| 3199 | Binder.restoreCallingIdentity(identity); |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | @Override |
| 3204 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3205 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3206 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3207 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3208 | } |
| 3209 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
| 3212 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3213 | Phone phone = getPhone(subId); |
| 3214 | if (phone == null) { |
| 3215 | loge("getImsProvisioningStatusForCapability: phone instance null for subid " |
| 3216 | + subId); |
| 3217 | // We will fail with "true" as the provisioning status because this is the default |
| 3218 | // if we do not require provisioning. |
| 3219 | return true; |
| 3220 | } |
| 3221 | |
| 3222 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3223 | return true; |
| 3224 | } |
| 3225 | |
| 3226 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3227 | switch (capability) { |
| 3228 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3229 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3230 | return ims.isVolteProvisionedOnDevice(); |
| 3231 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3232 | return ims.isWfcProvisionedOnDevice(); |
| 3233 | } |
| 3234 | // This should never happen, since we are checking tech above to make sure it |
| 3235 | // is either LTE or IWLAN. |
| 3236 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3237 | + "capability."); |
| 3238 | } |
| 3239 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3240 | // There is currently no difference in VT provisioning type. |
| 3241 | return ims.isVtProvisionedOnDevice(); |
| 3242 | } |
| 3243 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3244 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3245 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3246 | } |
| 3247 | default: { |
| 3248 | throw new IllegalArgumentException("Tried to get provisioning for capability '" |
| 3249 | + capability + "', which does not require provisioning."); |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | } finally { |
| 3254 | Binder.restoreCallingIdentity(identity); |
| 3255 | } |
| 3256 | } |
| 3257 | |
| 3258 | @Override |
| 3259 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3260 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3261 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3262 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3263 | } |
| 3264 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3265 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3266 | return (provisionedBits & capability) > 0; |
| 3267 | } |
| 3268 | |
| 3269 | @Override |
| 3270 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3271 | boolean isProvisioned) { |
| 3272 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3273 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3274 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3275 | } |
| 3276 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3277 | "setProvisioningStatusForCapability"); |
| 3278 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3279 | // If the current provisioning status for capability already matches isProvisioned, |
| 3280 | // do nothing. |
| 3281 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3282 | return; |
| 3283 | } |
| 3284 | if (isProvisioned) { |
| 3285 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3286 | } else { |
| 3287 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | /** |
| 3292 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3293 | * technology. The bitfield should mirror the bitfield defined by |
| 3294 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3295 | */ |
| 3296 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3297 | String key = getMmTelProvisioningKey(subId, tech); |
| 3298 | // Default is no capabilities are provisioned. |
| 3299 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3300 | } |
| 3301 | |
| 3302 | /** |
| 3303 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3304 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3305 | * technology specified. |
| 3306 | * |
| 3307 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3308 | */ |
| 3309 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3310 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3311 | String key = getMmTelProvisioningKey(subId, tech); |
| 3312 | editor.putInt(key, newField); |
| 3313 | editor.commit(); |
| 3314 | } |
| 3315 | |
| 3316 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3317 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3318 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3319 | } |
| 3320 | |
| 3321 | /** |
| 3322 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3323 | * carrier associated with the subscription id. |
| 3324 | */ |
| 3325 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3326 | int capability) { |
| 3327 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3328 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3329 | boolean requireUtProvisioning = c.getBoolean( |
| 3330 | // By default, this config is true (even if there is no SIM). We also check to make |
| 3331 | // sure the subscription needs provisioning here, so we do not need to check for |
| 3332 | // the no-SIM case, where we would normally shortcut this to false. |
| 3333 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true) |
| 3334 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3335 | false); |
| 3336 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3337 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3338 | |
| 3339 | // First check to make sure that the capability requires provisioning. |
| 3340 | switch (capability) { |
| 3341 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3342 | // intentional fallthrough |
| 3343 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3344 | if (requireVoiceVtProvisioning) { |
| 3345 | // Voice and Video requires provisioning |
| 3346 | return true; |
| 3347 | } |
| 3348 | break; |
| 3349 | } |
| 3350 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3351 | if (requireUtProvisioning) { |
| 3352 | // UT requires provisioning |
| 3353 | return true; |
| 3354 | } |
| 3355 | break; |
| 3356 | } |
| 3357 | } |
| 3358 | return false; |
| 3359 | } |
| 3360 | |
| 3361 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3362 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3363 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3364 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3365 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3366 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3367 | final long identity = Binder.clearCallingIdentity(); |
| 3368 | try { |
| 3369 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3370 | int slotId = getSlotIndex(subId); |
| 3371 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3372 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3373 | + subId + "' for key:" + key); |
| 3374 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3375 | } |
| 3376 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3377 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3378 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3379 | + subId + "' for key:" + key); |
| 3380 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
| 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | @Override |
| 3387 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3388 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3389 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3390 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3391 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3392 | final long identity = Binder.clearCallingIdentity(); |
| 3393 | try { |
| 3394 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3395 | int slotId = getSlotIndex(subId); |
| 3396 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3397 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3398 | + subId + "' for key:" + key); |
| 3399 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3400 | } |
| 3401 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3402 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3403 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3404 | + subId + "' for key:" + key); |
| 3405 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3406 | } finally { |
| 3407 | Binder.restoreCallingIdentity(identity); |
| 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | @Override |
| 3412 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3413 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3414 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3415 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3417 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3418 | final long identity = Binder.clearCallingIdentity(); |
| 3419 | try { |
| 3420 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3421 | int slotId = getSlotIndex(subId); |
| 3422 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3423 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3424 | + subId + "' for key:" + key); |
| 3425 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3426 | } |
| 3427 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3428 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3429 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3430 | + "' for key:" + key); |
| 3431 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3432 | } finally { |
| 3433 | Binder.restoreCallingIdentity(identity); |
| 3434 | } |
| 3435 | } |
| 3436 | |
| 3437 | @Override |
| 3438 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3439 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3440 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3441 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3442 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3443 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
| 3446 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3447 | int slotId = getSlotIndex(subId); |
| 3448 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3449 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3450 | + subId + "' for key:" + key); |
| 3451 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3452 | } |
| 3453 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3454 | } catch (ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3455 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3456 | + "' for key:" + key); |
| 3457 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3458 | } finally { |
| 3459 | Binder.restoreCallingIdentity(identity); |
| 3460 | } |
| 3461 | } |
| 3462 | |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3463 | private int getSlotIndexOrException(int subId) throws IllegalArgumentException { |
| 3464 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3465 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3466 | throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId); |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3467 | } |
| 3468 | return slotId; |
| 3469 | } |
| 3470 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3471 | private int getSlotIndex(int subId) { |
| 3472 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3473 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3474 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3475 | } |
| 3476 | return slotId; |
| 3477 | } |
| 3478 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3479 | /** |
| 3480 | * Returns the network type for a subId |
| 3481 | */ |
| 3482 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3483 | public int getNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3484 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3485 | mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3486 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3487 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3488 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3489 | final long identity = Binder.clearCallingIdentity(); |
| 3490 | try { |
| 3491 | final Phone phone = getPhone(subId); |
| 3492 | if (phone != null) { |
| 3493 | return phone.getServiceState().getDataNetworkType(); |
| 3494 | } else { |
| 3495 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3496 | } |
| 3497 | } finally { |
| 3498 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3499 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | /** |
| 3503 | * Returns the data network type |
| 3504 | */ |
| 3505 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3506 | public int getDataNetworkType(String callingPackage) { |
| 3507 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | /** |
| 3511 | * Returns the data network type for a subId |
| 3512 | */ |
| 3513 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3514 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3515 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3516 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3517 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3518 | } |
| 3519 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3520 | final long identity = Binder.clearCallingIdentity(); |
| 3521 | try { |
| 3522 | final Phone phone = getPhone(subId); |
| 3523 | if (phone != null) { |
| 3524 | return phone.getServiceState().getDataNetworkType(); |
| 3525 | } else { |
| 3526 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3527 | } |
| 3528 | } finally { |
| 3529 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3530 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3534 | * Returns the Voice network type for a subId |
| 3535 | */ |
| 3536 | @Override |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3537 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3538 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3539 | mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3540 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3541 | } |
| 3542 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3543 | final long identity = Binder.clearCallingIdentity(); |
| 3544 | try { |
| 3545 | final Phone phone = getPhone(subId); |
| 3546 | if (phone != null) { |
| 3547 | return phone.getServiceState().getVoiceNetworkType(); |
| 3548 | } else { |
| 3549 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3550 | } |
| 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3553 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | /** |
| 3557 | * @return true if a ICC card is present |
| 3558 | */ |
| 3559 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3560 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3561 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3562 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3566 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3567 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3568 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3569 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3570 | final long identity = Binder.clearCallingIdentity(); |
| 3571 | try { |
| 3572 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3573 | if (phone != null) { |
| 3574 | return phone.getIccCard().hasIccCard(); |
| 3575 | } else { |
| 3576 | return false; |
| 3577 | } |
| 3578 | } finally { |
| 3579 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 3580 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | /** |
| 3584 | * Return if the current radio is LTE on CDMA. This |
| 3585 | * is a tri-state return value as for a period of time |
| 3586 | * the mode may be unknown. |
| 3587 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3588 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3589 | * @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] | 3590 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3591 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3592 | @Override |
| 3593 | public int getLteOnCdmaMode(String callingPackage) { |
| 3594 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3597 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3598 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3600 | mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3601 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3602 | } |
| 3603 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3604 | final long identity = Binder.clearCallingIdentity(); |
| 3605 | try { |
| 3606 | final Phone phone = getPhone(subId); |
| 3607 | if (phone == null) { |
| 3608 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 3609 | } else { |
| 3610 | return phone.getLteOnCdmaMode(); |
| 3611 | } |
| 3612 | } finally { |
| 3613 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3614 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3617 | /** |
| 3618 | * {@hide} |
| 3619 | * Returns Default subId, 0 in the case of single standby. |
| 3620 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3621 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3622 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3625 | private int getSlotForDefaultSubscription() { |
| 3626 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 3627 | } |
| 3628 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3629 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 3630 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3631 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3632 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3633 | private boolean isActiveSubscription(int subId) { |
| 3634 | return mSubscriptionController.isActiveSubId(subId); |
| 3635 | } |
| 3636 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3637 | /** |
| 3638 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3639 | */ |
| 3640 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3641 | final long identity = Binder.clearCallingIdentity(); |
| 3642 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3643 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3644 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 3645 | getWhenToMakeWifiCallsDefaultPreference()); |
| 3646 | } finally { |
| 3647 | Binder.restoreCallingIdentity(identity); |
| 3648 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | /** |
| 3652 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 3653 | */ |
| 3654 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
| 3657 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3658 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3659 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 3660 | } finally { |
| 3661 | Binder.restoreCallingIdentity(identity); |
| 3662 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3663 | } |
| 3664 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 3665 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 3666 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 3667 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 3668 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 3669 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3670 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 3671 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 3672 | if (phoneId == -1) { |
| 3673 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 3674 | + " does not correspond to an active phone"); |
| 3675 | } |
| 3676 | return PhoneFactory.getPhone(phoneId); |
| 3677 | } |
| 3678 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3679 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3680 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 3681 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3683 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3684 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3685 | if (DBG) { |
| 3686 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 3687 | } |
| 3688 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 3689 | p2); |
| 3690 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3691 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3692 | |
| 3693 | @Override |
| 3694 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 3695 | int slotIndex, String callingPackage, String aid, int p2) { |
| 3696 | enforceModifyPermission(); |
| 3697 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3698 | if (DBG) { |
| 3699 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 3700 | } |
| 3701 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3702 | callingPackage, aid, p2); |
| 3703 | } |
| 3704 | |
| 3705 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 3706 | String callingPackage, String aid, int p2) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3707 | final long identity = Binder.clearCallingIdentity(); |
| 3708 | try { |
| 3709 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 3710 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3711 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3712 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3713 | if (bestComponent == null |
| 3714 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3715 | loge("The calling package is not allowed to access ISD-R."); |
| 3716 | throw new SecurityException( |
| 3717 | "The calling package is not allowed to access ISD-R."); |
| 3718 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3719 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 3720 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3721 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3722 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 3723 | null /* workSource */); |
| 3724 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3725 | return response; |
| 3726 | } finally { |
| 3727 | Binder.restoreCallingIdentity(identity); |
| 3728 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3732 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3734 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3735 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 3736 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 3737 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3738 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3739 | @Override |
| 3740 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 3741 | enforceModifyPermission(); |
| 3742 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 3743 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 3744 | channel); |
| 3745 | } |
| 3746 | |
| 3747 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3748 | final long identity = Binder.clearCallingIdentity(); |
| 3749 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | if (channel < 0) { |
| 3751 | return false; |
| 3752 | } |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3753 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 3754 | null /* workSource */); |
| 3755 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3756 | return success; |
| 3757 | } finally { |
| 3758 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3759 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3763 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3764 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3765 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3766 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3767 | if (DBG) { |
| 3768 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 3769 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3770 | + p3 + " data=" + data); |
| 3771 | } |
| 3772 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 3773 | command, p1, p2, p3, data); |
| 3774 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3775 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3776 | @Override |
| 3777 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 3778 | int command, int p1, int p2, int p3, String data) { |
| 3779 | enforceModifyPermission(); |
| 3780 | if (DBG) { |
| 3781 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 3782 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 3783 | + p3 + " data=" + data); |
| 3784 | } |
| 3785 | return iccTransmitApduLogicalChannelWithPermission( |
| 3786 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 3787 | data); |
| 3788 | } |
| 3789 | |
| 3790 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 3791 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | final long identity = Binder.clearCallingIdentity(); |
| 3793 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3794 | if (channel < 0) { |
| 3795 | return ""; |
| 3796 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3797 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3798 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3799 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 3800 | null /* workSource */); |
| 3801 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3802 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3803 | // Append the returned status code to the end of the response payload. |
| 3804 | String s = Integer.toHexString( |
| 3805 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3806 | if (response.payload != null) { |
| 3807 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3808 | } |
| 3809 | return s; |
| 3810 | } finally { |
| 3811 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3812 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 3813 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3814 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3815 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3816 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 3817 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3818 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3819 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3820 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3821 | if (DBG) { |
| 3822 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 3823 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 3824 | } |
| 3825 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 3826 | cla, command, p1, p2, p3, data); |
| 3827 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3828 | |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3829 | @Override |
| 3830 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 3831 | int command, int p1, int p2, int p3, String data) { |
| 3832 | enforceModifyPermission(); |
| 3833 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3834 | if (DBG) { |
| 3835 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 3836 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 3837 | + " data=" + data); |
| 3838 | } |
| 3839 | |
| 3840 | return iccTransmitApduBasicChannelWithPermission( |
| 3841 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 3842 | p2, p3, data); |
| 3843 | } |
| 3844 | |
| 3845 | // open APDU basic channel assuming the caller has sufficient permissions |
| 3846 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 3847 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3848 | final long identity = Binder.clearCallingIdentity(); |
| 3849 | try { |
| 3850 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 3851 | && TextUtils.equals(ISDR_AID, data)) { |
| 3852 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3853 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 3854 | .getContext().getPackageManager()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3855 | if (bestComponent == null |
| 3856 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 3857 | loge("The calling package is not allowed to select ISD-R."); |
| 3858 | throw new SecurityException( |
| 3859 | "The calling package is not allowed to select ISD-R."); |
| 3860 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3861 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 3862 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 73b078d | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 3864 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 3865 | null /* workSource */); |
| 3866 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3867 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3868 | // Append the returned status code to the end of the response payload. |
| 3869 | String s = Integer.toHexString( |
| 3870 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3871 | if (response.payload != null) { |
| 3872 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3873 | } |
| 3874 | return s; |
| 3875 | } finally { |
| 3876 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 3877 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3881 | 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] | 3882 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3883 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3884 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3885 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3886 | final long identity = Binder.clearCallingIdentity(); |
| 3887 | try { |
| 3888 | if (DBG) { |
| 3889 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 3890 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 3891 | } |
| 3892 | |
| 3893 | IccIoResult response = |
| 3894 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 3895 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 3896 | subId); |
| 3897 | |
| 3898 | if (DBG) { |
| 3899 | log("Exchange SIM_IO [R]" + response); |
| 3900 | } |
| 3901 | |
| 3902 | byte[] result = null; |
| 3903 | int length = 2; |
| 3904 | if (response.payload != null) { |
| 3905 | length = 2 + response.payload.length; |
| 3906 | result = new byte[length]; |
| 3907 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 3908 | } else { |
| 3909 | result = new byte[length]; |
| 3910 | } |
| 3911 | |
| 3912 | result[length - 1] = (byte) response.sw2; |
| 3913 | result[length - 2] = (byte) response.sw1; |
| 3914 | return result; |
| 3915 | } finally { |
| 3916 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3917 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3920 | /** |
| 3921 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 3922 | * on a particular subscription |
| 3923 | */ |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 3924 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) { |
| 3925 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 3926 | mApp, subId, callingPackage, "getForbiddenPlmns")) { |
| 3927 | return null; |
| 3928 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3929 | |
| 3930 | final long identity = Binder.clearCallingIdentity(); |
| 3931 | try { |
| 3932 | if (appType != TelephonyManager.APPTYPE_USIM |
| 3933 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 3934 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 3935 | return null; |
| 3936 | } |
| 3937 | Object response = sendRequest( |
| 3938 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 3939 | if (response instanceof String[]) { |
| 3940 | return (String[]) response; |
| 3941 | } |
| 3942 | // Response is an Exception of some kind, |
| 3943 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3944 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3945 | } finally { |
| 3946 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3947 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 3948 | } |
| 3949 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 3950 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 3951 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3952 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3953 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3954 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | final long identity = Binder.clearCallingIdentity(); |
| 3956 | try { |
| 3957 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 3958 | if (response.payload == null) { |
| 3959 | return ""; |
| 3960 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3961 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3962 | // Append the returned status code to the end of the response payload. |
| 3963 | String s = Integer.toHexString( |
| 3964 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 3965 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 3966 | return s; |
| 3967 | } finally { |
| 3968 | Binder.restoreCallingIdentity(identity); |
| 3969 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3972 | /** |
| 3973 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3974 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3975 | * |
| 3976 | * @param itemID the ID of the item to read |
| 3977 | * @return the NV item as a String, or null on error. |
| 3978 | */ |
| 3979 | @Override |
| 3980 | public String nvReadItem(int itemID) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3981 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3983 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3984 | |
| 3985 | final long identity = Binder.clearCallingIdentity(); |
| 3986 | try { |
| 3987 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 3988 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3989 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 3990 | return value; |
| 3991 | } finally { |
| 3992 | Binder.restoreCallingIdentity(identity); |
| 3993 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | /** |
| 3997 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 3998 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 3999 | * |
| 4000 | * @param itemID the ID of the item to read |
| 4001 | * @param itemValue the value to write, as a String |
| 4002 | * @return true on success; false on any failure |
| 4003 | */ |
| 4004 | @Override |
| 4005 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4006 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4007 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4008 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4009 | |
| 4010 | final long identity = Binder.clearCallingIdentity(); |
| 4011 | try { |
| 4012 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4013 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4014 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4015 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4016 | return success; |
| 4017 | } finally { |
| 4018 | Binder.restoreCallingIdentity(identity); |
| 4019 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | /** |
| 4023 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4024 | * Used for device configuration by some CDMA operators. |
| 4025 | * |
| 4026 | * @param preferredRoamingList byte array containing the new PRL |
| 4027 | * @return true on success; false on any failure |
| 4028 | */ |
| 4029 | @Override |
| 4030 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4032 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4033 | |
| 4034 | final long identity = Binder.clearCallingIdentity(); |
| 4035 | try { |
| 4036 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4037 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4038 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4039 | return success; |
| 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(identity); |
| 4042 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | /** |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4046 | * 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] | 4047 | * Used for device configuration by some CDMA operators. |
| 4048 | * |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4049 | * @param slotIndex - device slot. |
| 4050 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4051 | * @return true on success; false on any failure |
| 4052 | */ |
| 4053 | @Override |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4054 | public boolean resetModemConfig(int slotIndex) { |
| 4055 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4056 | if (phone != null) { |
| 4057 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4058 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4059 | |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4060 | final long identity = Binder.clearCallingIdentity(); |
| 4061 | try { |
| 4062 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4063 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4064 | return success; |
| 4065 | } finally { |
| 4066 | Binder.restoreCallingIdentity(identity); |
| 4067 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 | } |
chen xu | 1cc0abe | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4069 | return false; |
| 4070 | } |
| 4071 | |
| 4072 | /** |
| 4073 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4074 | * |
| 4075 | * @param slotIndex - device slot. |
| 4076 | * |
| 4077 | * @return true on success; false on any failure |
| 4078 | */ |
| 4079 | @Override |
| 4080 | public boolean rebootModem(int slotIndex) { |
| 4081 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4082 | if (phone != null) { |
| 4083 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4084 | mApp, phone.getSubId(), "rebootModem"); |
| 4085 | |
| 4086 | final long identity = Binder.clearCallingIdentity(); |
| 4087 | try { |
| 4088 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4089 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4090 | return success; |
| 4091 | } finally { |
| 4092 | Binder.restoreCallingIdentity(identity); |
| 4093 | } |
| 4094 | } |
| 4095 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4096 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4097 | |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4098 | public String[] getPcscfAddress(String apnType, String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4099 | final Phone defaultPhone = getDefaultPhone(); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4100 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4101 | mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4102 | return new String[0]; |
| 4103 | } |
| 4104 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4105 | final long identity = Binder.clearCallingIdentity(); |
| 4106 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4107 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4108 | } finally { |
| 4109 | Binder.restoreCallingIdentity(identity); |
| 4110 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4111 | } |
| 4112 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4113 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4114 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4115 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4116 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4117 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4118 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4119 | |
| 4120 | final long identity = Binder.clearCallingIdentity(); |
| 4121 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4122 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4123 | if (resolver == null) { |
| 4124 | // may happen if the device does not support IMS. |
| 4125 | return; |
| 4126 | } |
| 4127 | resolver.enableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4128 | } finally { |
| 4129 | Binder.restoreCallingIdentity(identity); |
| 4130 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4134 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4135 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4136 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4137 | public void disableIms(int slotId) { |
| 4138 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4139 | |
| 4140 | final long identity = Binder.clearCallingIdentity(); |
| 4141 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4142 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4143 | if (resolver == null) { |
| 4144 | // may happen if the device does not support IMS. |
| 4145 | return; |
| 4146 | } |
| 4147 | resolver.disableIms(slotId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | } finally { |
| 4149 | Binder.restoreCallingIdentity(identity); |
| 4150 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | /** |
| 4154 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4155 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4156 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4157 | */ |
| 4158 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4159 | IImsServiceFeatureCallback callback) { |
| 4160 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4161 | |
| 4162 | final long identity = Binder.clearCallingIdentity(); |
| 4163 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4164 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4165 | if (resolver == null) { |
| 4166 | // may happen if the device does not support IMS. |
| 4167 | return null; |
| 4168 | } |
| 4169 | return resolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4170 | } finally { |
| 4171 | Binder.restoreCallingIdentity(identity); |
| 4172 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | /** |
| 4176 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4177 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4178 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4179 | * listener for feature updates. |
| 4180 | */ |
| 4181 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4182 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | |
| 4184 | final long identity = Binder.clearCallingIdentity(); |
| 4185 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4186 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4187 | if (resolver == null) { |
| 4188 | // may happen if the device does not support IMS. |
| 4189 | return null; |
| 4190 | } |
| 4191 | return resolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4192 | } finally { |
| 4193 | Binder.restoreCallingIdentity(identity); |
| 4194 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4195 | } |
| 4196 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4197 | /** |
| 4198 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4199 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4200 | */ |
| 4201 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4202 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4203 | |
| 4204 | final long identity = Binder.clearCallingIdentity(); |
| 4205 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4206 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4207 | if (resolver == null) { |
| 4208 | // may happen if the device does not support IMS. |
| 4209 | return null; |
| 4210 | } |
| 4211 | return resolver.getImsRegistration(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4212 | } finally { |
| 4213 | Binder.restoreCallingIdentity(identity); |
| 4214 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4215 | } |
| 4216 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4217 | /** |
| 4218 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4219 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4220 | */ |
| 4221 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4222 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4223 | |
| 4224 | final long identity = Binder.clearCallingIdentity(); |
| 4225 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4226 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4227 | if (resolver == null) { |
| 4228 | // may happen if the device does not support IMS. |
| 4229 | return null; |
| 4230 | } |
| 4231 | return resolver.getImsConfig(slotId, feature); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4232 | } finally { |
| 4233 | Binder.restoreCallingIdentity(identity); |
| 4234 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4235 | } |
| 4236 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4237 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4238 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4239 | * |
| 4240 | * @param slotId the slot ID that the ImsService should bind for. |
| 4241 | * @param isCarrierImsService true if the ImsService is the carrier override, false if the |
| 4242 | * ImsService is the device default ImsService. |
| 4243 | * @param packageName The package name of the application that contains the ImsService to bind |
| 4244 | * to. |
| 4245 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
| 4246 | * @hide |
| 4247 | */ |
| 4248 | public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4249 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4250 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4251 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4252 | "setImsService"); |
| 4253 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4254 | final long identity = Binder.clearCallingIdentity(); |
| 4255 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4256 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4257 | if (resolver == null) { |
| 4258 | // may happen if the device does not support IMS. |
| 4259 | return false; |
| 4260 | } |
| 4261 | return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService, |
| 4262 | packageName); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4263 | } finally { |
| 4264 | Binder.restoreCallingIdentity(identity); |
| 4265 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | /** |
| 4269 | * Return the ImsService configuration. |
| 4270 | * |
| 4271 | * @param slotId The slot that the ImsService is associated with. |
| 4272 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4273 | * the device default. |
| 4274 | * @return the package name of the ImsService configuration. |
| 4275 | */ |
| 4276 | public String getImsService(int slotId, boolean isCarrierImsService) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4277 | int[] subIds = SubscriptionManager.getSubId(slotId); |
| 4278 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4279 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4280 | "getImsService"); |
| 4281 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4282 | final long identity = Binder.clearCallingIdentity(); |
| 4283 | try { |
Brad Ebinger | eb160e2 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4284 | ImsResolver resolver = PhoneFactory.getImsResolver(); |
| 4285 | if (resolver == null) { |
| 4286 | // may happen if the device does not support IMS. |
| 4287 | return ""; |
| 4288 | } |
| 4289 | return resolver.getImsServiceConfiguration(slotId, isCarrierImsService); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4290 | } finally { |
| 4291 | Binder.restoreCallingIdentity(identity); |
| 4292 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4293 | } |
| 4294 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4295 | public void setImsRegistrationState(boolean registered) { |
| 4296 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4297 | |
| 4298 | final long identity = Binder.clearCallingIdentity(); |
| 4299 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4300 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4301 | } finally { |
| 4302 | Binder.restoreCallingIdentity(identity); |
| 4303 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4307 | * Set the network selection mode to automatic. |
| 4308 | * |
| 4309 | */ |
| 4310 | @Override |
| 4311 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4312 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4313 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4314 | |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4315 | if (!isActiveSubscription(subId)) { |
| 4316 | return; |
| 4317 | } |
| 4318 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4319 | final long identity = Binder.clearCallingIdentity(); |
| 4320 | try { |
| 4321 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4322 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4323 | } finally { |
| 4324 | Binder.restoreCallingIdentity(identity); |
| 4325 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4328 | /** |
| 4329 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4330 | * |
| 4331 | * @param subId the id of the subscription. |
| 4332 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4333 | * the operator to attach to. |
| 4334 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4335 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4336 | * normal network selection next time. |
| 4337 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4338 | */ |
| 4339 | @Override |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4340 | public boolean setNetworkSelectionModeManual( |
| 4341 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4342 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4343 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | 466e248 | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4344 | |
| 4345 | if (!isActiveSubscription(subId)) { |
| 4346 | return false; |
| 4347 | } |
| 4348 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4349 | final long identity = Binder.clearCallingIdentity(); |
| 4350 | try { |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4351 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4352 | persistSelection); |
Pengquan Meng | a4d9cff | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4353 | if (DBG) { |
| 4354 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4355 | + " operator: " + operatorInfo); |
| 4356 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4357 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
| 4360 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | /** |
| 4364 | * Scans for available networks. |
| 4365 | */ |
| 4366 | @Override |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4367 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4369 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4370 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4371 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4372 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4373 | .setCallingPackage(callingPackage) |
| 4374 | .setCallingPid(Binder.getCallingPid()) |
| 4375 | .setCallingUid(Binder.getCallingUid()) |
| 4376 | .setMethod("getCellNetworkScanResults") |
| 4377 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4378 | .build()); |
| 4379 | switch (locationResult) { |
| 4380 | case DENIED_HARD: |
| 4381 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4382 | case DENIED_SOFT: |
| 4383 | return null; |
| 4384 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4385 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4386 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4387 | try { |
| 4388 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4389 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4390 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4391 | } finally { |
| 4392 | Binder.restoreCallingIdentity(identity); |
| 4393 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4397 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4398 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4399 | * @param subId id of the subscription |
| 4400 | * @param request contains the radio access networks with bands/channels to scan |
| 4401 | * @param messenger callback messenger for scan results or errors |
| 4402 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4403 | * @return the id of the requested scan which can be used to stop the scan. |
| 4404 | */ |
| 4405 | @Override |
| 4406 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4407 | IBinder binder, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4408 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4409 | mApp, subId, "requestNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4410 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4411 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4412 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4413 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4414 | .setCallingPackage(callingPackage) |
| 4415 | .setCallingPid(Binder.getCallingPid()) |
| 4416 | .setCallingUid(Binder.getCallingUid()) |
| 4417 | .setMethod("requestNetworkScan") |
| 4418 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4419 | .build()); |
| 4420 | switch (locationResult) { |
| 4421 | case DENIED_HARD: |
| 4422 | throw new SecurityException("Not allowed to request network scan -- location"); |
| 4423 | case DENIED_SOFT: |
| 4424 | return -1; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4425 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4426 | |
| 4427 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4428 | request, messenger, binder, getPhone(subId), |
| 4429 | callingPackage); |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | /** |
| 4433 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4434 | * |
| 4435 | * @param subId id of the subscription |
| 4436 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4437 | */ |
| 4438 | @Override |
| 4439 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4440 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4441 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | |
| 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
| 4445 | mNetworkScanRequestTracker.stopNetworkScan(scanId); |
| 4446 | } finally { |
| 4447 | Binder.restoreCallingIdentity(identity); |
| 4448 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4452 | * Get the calculated preferred network type. |
| 4453 | * Used for debugging incorrect network type. |
| 4454 | * |
| 4455 | * @return the preferred network type, defined in RILConstants.java. |
| 4456 | */ |
| 4457 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4458 | public int getCalculatedPreferredNetworkType(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4459 | final Phone defaultPhone = getDefaultPhone(); |
| 4460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4461 | callingPackage, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4462 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 4463 | } |
| 4464 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4465 | final long identity = Binder.clearCallingIdentity(); |
| 4466 | try { |
| 4467 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4468 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4469 | } finally { |
| 4470 | Binder.restoreCallingIdentity(identity); |
| 4471 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4475 | * Get the preferred network type. |
| 4476 | * Used for device configuration by some CDMA operators. |
| 4477 | * |
| 4478 | * @return the preferred network type, defined in RILConstants.java. |
| 4479 | */ |
| 4480 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4481 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | 4848cd0 | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 4482 | TelephonyPermissions |
| 4483 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4484 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | |
| 4486 | final long identity = Binder.clearCallingIdentity(); |
| 4487 | try { |
| 4488 | if (DBG) log("getPreferredNetworkType"); |
| 4489 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 4490 | int networkType = (result != null ? result[0] : -1); |
| 4491 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 4492 | return networkType; |
| 4493 | } finally { |
| 4494 | Binder.restoreCallingIdentity(identity); |
| 4495 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | /** |
| 4499 | * Set the preferred network type. |
| 4500 | * Used for device configuration by some CDMA operators. |
| 4501 | * |
| 4502 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 4503 | * @return true on success; false on any failure. |
| 4504 | */ |
| 4505 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4506 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4507 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4508 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4509 | |
| 4510 | final long identity = Binder.clearCallingIdentity(); |
| 4511 | try { |
| 4512 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 4513 | Boolean success = (Boolean) sendRequest( |
| 4514 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 4515 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 4516 | if (success) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4517 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4518 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 4519 | } |
| 4520 | return success; |
| 4521 | } finally { |
| 4522 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 4523 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4524 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4525 | |
| 4526 | /** |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4527 | * Check whether DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4528 | * |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4529 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4530 | * @hide |
| 4531 | */ |
| 4532 | @Override |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4533 | public boolean getTetherApnRequired() { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4534 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4535 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4536 | final Phone defaultPhone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4537 | try { |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 4538 | return defaultPhone.hasMatchedTetherApnSetting(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4539 | } finally { |
| 4540 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4541 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4545 | * Set mobile data enabled |
| 4546 | * Used by the user through settings etc to turn on/off mobile data |
| 4547 | * |
| 4548 | * @param enable {@code true} turn turn data on, else {@code false} |
| 4549 | */ |
| 4550 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4551 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4553 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4554 | |
| 4555 | final long identity = Binder.clearCallingIdentity(); |
| 4556 | try { |
| 4557 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4558 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4559 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4560 | if (phone != null) { |
| 4561 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4562 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4563 | } else { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4564 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4565 | } |
| 4566 | } finally { |
| 4567 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4568 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4572 | * Get the user enabled state of Mobile Data. |
| 4573 | * |
| 4574 | * TODO: remove and use isUserDataEnabled. |
| 4575 | * This can't be removed now because some vendor codes |
| 4576 | * calls through ITelephony directly while they should |
| 4577 | * use TelephonyManager. |
| 4578 | * |
| 4579 | * @return true on enabled |
| 4580 | */ |
| 4581 | @Override |
| 4582 | public boolean getDataEnabled(int subId) { |
| 4583 | return isUserDataEnabled(subId); |
| 4584 | } |
| 4585 | |
| 4586 | /** |
| 4587 | * Get whether mobile data is enabled per user setting. |
| 4588 | * |
| 4589 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 4590 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4591 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 4592 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4593 | * |
| 4594 | * @return {@code true} if data is enabled else {@code false} |
| 4595 | */ |
| 4596 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4597 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4598 | try { |
| 4599 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4600 | null); |
| 4601 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4603 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 4604 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4605 | |
| 4606 | final long identity = Binder.clearCallingIdentity(); |
| 4607 | try { |
| 4608 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4609 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4610 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4611 | if (phone != null) { |
| 4612 | boolean retVal = phone.isUserDataEnabled(); |
| 4613 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4614 | return retVal; |
| 4615 | } else { |
| 4616 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4617 | return false; |
| 4618 | } |
| 4619 | } finally { |
| 4620 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | /** |
| 4625 | * Get whether mobile data is enabled. |
| 4626 | * |
| 4627 | * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding |
| 4628 | * whether mobile data is actually enabled. |
| 4629 | * |
| 4630 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
| 4631 | * |
| 4632 | * @return {@code true} if data is enabled else {@code false} |
| 4633 | */ |
| 4634 | @Override |
| 4635 | public boolean isDataEnabled(int subId) { |
| 4636 | try { |
| 4637 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 4638 | null); |
| 4639 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4641 | mApp, subId, "isDataEnabled"); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 4642 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4643 | |
| 4644 | final long identity = Binder.clearCallingIdentity(); |
| 4645 | try { |
| 4646 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 4647 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 4648 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 4649 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 4650 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4651 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 4652 | return retVal; |
| 4653 | } else { |
| 4654 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 4655 | return false; |
| 4656 | } |
| 4657 | } finally { |
| 4658 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 4659 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 4660 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4661 | |
| 4662 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4663 | public int getCarrierPrivilegeStatus(int subId) { |
| 4664 | final Phone phone = getPhone(subId); |
| 4665 | if (phone == null) { |
| 4666 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 4667 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 4668 | } |
| 4669 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4670 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 4671 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4672 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4673 | } |
| 4674 | return card.getCarrierPrivilegeStatusForCurrentTransaction( |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4675 | phone.getContext().getPackageManager()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 4676 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4677 | |
| 4678 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4679 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
| 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 | UiccProfile profile = |
| 4686 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 4687 | if (profile == null) { |
| 4688 | loge("getCarrierPrivilegeStatus: No UICC"); |
| 4689 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4690 | } |
| 4691 | return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid); |
| 4692 | } |
| 4693 | |
| 4694 | @Override |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4695 | public int checkCarrierPrivilegesForPackage(String pkgName) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4696 | final Phone defaultPhone = getDefaultPhone(); |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4697 | if (TextUtils.isEmpty(pkgName)) |
| 4698 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4699 | UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 4700 | if (card == null) { |
| 4701 | loge("checkCarrierPrivilegesForPackage: No UICC"); |
| 4702 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4703 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4704 | return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(), |
| 4705 | pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | @Override |
| 4709 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 4710 | if (TextUtils.isEmpty(pkgName)) |
| 4711 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4712 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 4713 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4714 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4715 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 4716 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4717 | continue; |
| 4718 | } |
| 4719 | |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4720 | result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 4721 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4722 | break; |
| 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 4727 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 4728 | |
| 4729 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 4730 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 4731 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 4732 | loge("phoneId " + phoneId + " is not valid."); |
| 4733 | return null; |
| 4734 | } |
| 4735 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4736 | if (card == null) { |
Diego Pontoriero | af74c86 | 2014-08-28 11:51:16 -0700 | [diff] [blame] | 4737 | loge("getCarrierPackageNamesForIntent: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4738 | return null ; |
| 4739 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4740 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4741 | } |
| 4742 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4743 | @Override |
| 4744 | public List<String> getPackagesWithCarrierPrivileges() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4745 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 4746 | List<String> privilegedPackages = new ArrayList<>(); |
| 4747 | List<PackageInfo> packages = null; |
| 4748 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 4749 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 4750 | if (card == null) { |
| 4751 | // No UICC in that slot. |
| 4752 | continue; |
| 4753 | } |
| 4754 | if (card.hasCarrierPrivilegeRules()) { |
| 4755 | if (packages == null) { |
| 4756 | // Only check packages in user 0 for now |
| 4757 | packages = pm.getInstalledPackagesAsUser( |
| 4758 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 4759 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
| 4760 | | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); |
| 4761 | } |
| 4762 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 4763 | PackageInfo pkgInfo = packages.get(p); |
| 4764 | if (pkgInfo != null && pkgInfo.packageName != null |
| 4765 | && card.getCarrierPrivilegeStatus(pkgInfo) |
| 4766 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 4767 | privilegedPackages.add(pkgInfo.packageName); |
| 4768 | } |
| 4769 | } |
| 4770 | } |
| 4771 | } |
| 4772 | return privilegedPackages; |
| 4773 | } |
| 4774 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4775 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4776 | final Phone phone = getPhone(subId); |
| 4777 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4778 | if (card == null) { |
| 4779 | loge("getIccId: No UICC"); |
| 4780 | return null; |
| 4781 | } |
| 4782 | String iccId = card.getIccId(); |
| 4783 | if (TextUtils.isEmpty(iccId)) { |
| 4784 | loge("getIccId: ICC ID is null or empty."); |
| 4785 | return null; |
| 4786 | } |
| 4787 | return iccId; |
| 4788 | } |
| 4789 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 4790 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4791 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 4792 | String number) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4793 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4794 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4795 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4796 | final long identity = Binder.clearCallingIdentity(); |
| 4797 | try { |
| 4798 | final String iccId = getIccId(subId); |
| 4799 | final Phone phone = getPhone(subId); |
| 4800 | if (phone == null) { |
| 4801 | return false; |
| 4802 | } |
| 4803 | final String subscriberId = phone.getSubscriberId(); |
| 4804 | |
| 4805 | if (DBG_MERGE) { |
| 4806 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 4807 | + subscriberId + " to " + number); |
| 4808 | } |
| 4809 | |
| 4810 | if (TextUtils.isEmpty(iccId)) { |
| 4811 | return false; |
| 4812 | } |
| 4813 | |
| 4814 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4815 | |
| 4816 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4817 | if (alphaTag == null) { |
| 4818 | editor.remove(alphaTagPrefKey); |
| 4819 | } else { |
| 4820 | editor.putString(alphaTagPrefKey, alphaTag); |
| 4821 | } |
| 4822 | |
| 4823 | // Record both the line number and IMSI for this ICCID, since we need to |
| 4824 | // track all merged IMSIs based on line number |
| 4825 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4826 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4827 | if (number == null) { |
| 4828 | editor.remove(numberPrefKey); |
| 4829 | editor.remove(subscriberPrefKey); |
| 4830 | } else { |
| 4831 | editor.putString(numberPrefKey, number); |
| 4832 | editor.putString(subscriberPrefKey, subscriberId); |
| 4833 | } |
| 4834 | |
| 4835 | editor.commit(); |
| 4836 | return true; |
| 4837 | } finally { |
| 4838 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4839 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4843 | public String getLine1NumberForDisplay(int subId, String callingPackage) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 4844 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4845 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4846 | mApp, subId, callingPackage, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4847 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4848 | return null; |
| 4849 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4850 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4851 | final long identity = Binder.clearCallingIdentity(); |
| 4852 | try { |
| 4853 | String iccId = getIccId(subId); |
| 4854 | if (iccId != null) { |
| 4855 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4856 | if (DBG_MERGE) { |
| 4857 | log("getLine1NumberForDisplay returning " |
| 4858 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 4859 | } |
| 4860 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 4861 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4862 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 4863 | return null; |
| 4864 | } finally { |
| 4865 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4866 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4870 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4871 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4872 | mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4873 | return null; |
| 4874 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 4875 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4876 | final long identity = Binder.clearCallingIdentity(); |
| 4877 | try { |
| 4878 | String iccId = getIccId(subId); |
| 4879 | if (iccId != null) { |
| 4880 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 4881 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 4882 | } |
| 4883 | return null; |
| 4884 | } finally { |
| 4885 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4886 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 4887 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4888 | |
| 4889 | @Override |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4890 | public String[] getMergedSubscriberIds(String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4891 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 4892 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4893 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 4894 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
| 4895 | "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4896 | return null; |
| 4897 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4898 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4899 | final long identity = Binder.clearCallingIdentity(); |
| 4900 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4901 | final Context context = mApp; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4902 | final TelephonyManager tele = TelephonyManager.from(context); |
| 4903 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 4904 | |
| 4905 | // Figure out what subscribers are currently active |
| 4906 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
| 4907 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 4908 | // the process, where TelephonyManager was instantiated. |
| 4909 | // Otherwise AppOps check will fail. |
| 4910 | |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4911 | final int[] subIds = sub.getActiveSubscriptionIdList(); |
| 4912 | for (int subId : subIds) { |
| 4913 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 4914 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4915 | |
| 4916 | // First pass, find a number override for an active subscriber |
| 4917 | String mergeNumber = null; |
| 4918 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 4919 | for (String key : prefs.keySet()) { |
| 4920 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 4921 | final String subscriberId = (String) prefs.get(key); |
| 4922 | if (activeSubscriberIds.contains(subscriberId)) { |
| 4923 | final String iccId = key.substring( |
| 4924 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 4925 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 4926 | mergeNumber = (String) prefs.get(numberKey); |
| 4927 | if (DBG_MERGE) { |
| 4928 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 4929 | + " for active subscriber " + subscriberId); |
| 4930 | } |
| 4931 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 4932 | break; |
| 4933 | } |
| 4934 | } |
| 4935 | } |
| 4936 | } |
| 4937 | |
| 4938 | // Shortcut when no active merged subscribers |
| 4939 | if (TextUtils.isEmpty(mergeNumber)) { |
| 4940 | return null; |
| 4941 | } |
| 4942 | |
| 4943 | // Second pass, find all subscribers under that line override |
| 4944 | final ArraySet<String> result = new ArraySet<>(); |
| 4945 | for (String key : prefs.keySet()) { |
| 4946 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 4947 | final String number = (String) prefs.get(key); |
| 4948 | if (mergeNumber.equals(number)) { |
| 4949 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 4950 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 4951 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 4952 | if (!TextUtils.isEmpty(subscriberId)) { |
| 4953 | result.add(subscriberId); |
| 4954 | } |
| 4955 | } |
| 4956 | } |
| 4957 | } |
| 4958 | |
| 4959 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 4960 | Arrays.sort(resultArray); |
| 4961 | if (DBG_MERGE) { |
| 4962 | Slog.d(LOG_TAG, |
| 4963 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 4964 | } |
| 4965 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 4966 | } finally { |
| 4967 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4968 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4972 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4973 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4974 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | |
| 4976 | final long identity = Binder.clearCallingIdentity(); |
| 4977 | try { |
| 4978 | final Phone phone = getPhone(subId); |
| 4979 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 4980 | } finally { |
| 4981 | Binder.restoreCallingIdentity(identity); |
| 4982 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 4983 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 4984 | |
| 4985 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4986 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 4987 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 4988 | List<String> cdmaNonRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4989 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4990 | |
| 4991 | final long identity = Binder.clearCallingIdentity(); |
| 4992 | try { |
| 4993 | final Phone phone = getPhone(subId); |
| 4994 | if (phone == null) { |
| 4995 | return false; |
| 4996 | } |
| 4997 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 4998 | cdmaNonRoamingList); |
| 4999 | } finally { |
| 5000 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5001 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5002 | } |
| 5003 | |
| 5004 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5005 | @Deprecated |
| 5006 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5007 | enforceModifyPermission(); |
| 5008 | |
| 5009 | int returnValue = 0; |
| 5010 | try { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5011 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5012 | if(result.exception == null) { |
| 5013 | if (result.result != null) { |
| 5014 | byte[] responseData = (byte[])(result.result); |
| 5015 | if(responseData.length > oemResp.length) { |
| 5016 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5017 | responseData.length + "bytes. Buffer Size is " + |
| 5018 | oemResp.length + "bytes."); |
| 5019 | } |
| 5020 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5021 | returnValue = responseData.length; |
| 5022 | } |
| 5023 | } else { |
| 5024 | CommandException ex = (CommandException) result.exception; |
| 5025 | returnValue = ex.getCommandError().ordinal(); |
| 5026 | if(returnValue > 0) returnValue *= -1; |
| 5027 | } |
| 5028 | } catch (RuntimeException e) { |
| 5029 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5030 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5031 | if(returnValue > 0) returnValue *= -1; |
| 5032 | } |
| 5033 | |
| 5034 | return returnValue; |
| 5035 | } |
| 5036 | |
| 5037 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5038 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5039 | try { |
| 5040 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5041 | } catch (RuntimeException e) { |
| 5042 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5047 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5048 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5049 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5050 | if (phone == null) { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5051 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5052 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5053 | final long identity = Binder.clearCallingIdentity(); |
| 5054 | try { |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5055 | TelephonyPermissions |
| 5056 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5057 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5058 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
| 5061 | } |
chen xu | feeed75 | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5062 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5063 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5064 | |
| 5065 | @Override |
| 5066 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5067 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5068 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | |
| 5070 | final long identity = Binder.clearCallingIdentity(); |
| 5071 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5072 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5073 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | } finally { |
| 5075 | Binder.restoreCallingIdentity(identity); |
| 5076 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5080 | public boolean isVideoCallingEnabled(String callingPackage) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5081 | final Phone defaultPhone = getDefaultPhone(); |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5082 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5083 | mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5084 | return false; |
| 5085 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5086 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5087 | final long identity = Binder.clearCallingIdentity(); |
| 5088 | try { |
| 5089 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5090 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5091 | // In the long run, we may instead need to check if there exists a connection service |
| 5092 | // which can support video calling. |
| 5093 | ImsManager imsManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5094 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 | return imsManager.isVtEnabledByPlatform() |
| 5096 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5097 | && imsManager.isVtEnabledByUser(); |
| 5098 | } finally { |
| 5099 | Binder.restoreCallingIdentity(identity); |
| 5100 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5101 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5102 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5103 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5104 | public boolean canChangeDtmfToneLength(int subId, String callingPackage) { |
| 5105 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5106 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5107 | return false; |
| 5108 | } |
| 5109 | |
| 5110 | final long identity = Binder.clearCallingIdentity(); |
| 5111 | try { |
| 5112 | CarrierConfigManager configManager = |
| 5113 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5114 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5115 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5116 | } finally { |
| 5117 | Binder.restoreCallingIdentity(identity); |
| 5118 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | @Override |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5122 | public boolean isWorldPhone(int subId, String callingPackage) { |
| 5123 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5124 | mApp, subId, callingPackage, "isVideoCallingEnabled")) { |
| 5125 | return false; |
| 5126 | } |
| 5127 | |
| 5128 | final long identity = Binder.clearCallingIdentity(); |
| 5129 | try { |
| 5130 | CarrierConfigManager configManager = |
| 5131 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5132 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5133 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5134 | } finally { |
| 5135 | Binder.restoreCallingIdentity(identity); |
| 5136 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5137 | } |
| 5138 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5139 | @Override |
| 5140 | public boolean isTtyModeSupported() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5141 | TelecomManager telecomManager = TelecomManager.from(mApp); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5142 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | @Override |
| 5146 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5149 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(identity); |
| 5152 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5153 | } |
| 5154 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5155 | /** |
| 5156 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5157 | * support for the feature and device firmware support. |
| 5158 | * |
| 5159 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5160 | */ |
| 5161 | @Override |
| 5162 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5164 | final Phone phone = getPhone(subscriptionId); |
| 5165 | if (phone == null) { |
| 5166 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5167 | return false; |
| 5168 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5169 | try { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5170 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5171 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5172 | boolean isDeviceSupported = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5173 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | return isCarrierSupported && isDeviceSupported; |
| 5175 | } finally { |
| 5176 | Binder.restoreCallingIdentity(identity); |
| 5177 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5178 | } |
| 5179 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5180 | /** |
| 5181 | * Determines whether the user has turned on RTT. Only returns true if the device and carrier |
| 5182 | * both also support RTT. |
| 5183 | */ |
| 5184 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5187 | return isRttSupported(subscriptionId) && Settings.Secure.getInt( |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5188 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5189 | } finally { |
| 5190 | Binder.restoreCallingIdentity(identity); |
| 5191 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5192 | } |
| 5193 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5194 | /** |
| 5195 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5196 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5197 | * |
| 5198 | * <p>Requires Permission: |
| 5199 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5200 | */ |
| 5201 | @Override |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5202 | public String getDeviceId(String callingPackage) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5203 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5204 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5205 | return null; |
| 5206 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5207 | int subId = phone.getSubId(); |
| 5208 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5209 | mApp, subId, callingPackage, "getDeviceId")) { |
| 5210 | return null; |
| 5211 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5212 | |
| 5213 | final long identity = Binder.clearCallingIdentity(); |
| 5214 | try { |
| 5215 | return phone.getDeviceId(); |
| 5216 | } finally { |
| 5217 | Binder.restoreCallingIdentity(identity); |
| 5218 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5219 | } |
| 5220 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5221 | /** |
| 5222 | * {@hide} |
| 5223 | * Returns the IMS Registration Status on a particular subid |
| 5224 | * |
| 5225 | * @param subId |
| 5226 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5227 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5228 | Phone phone = getPhone(subId); |
| 5229 | if (phone != null) { |
| 5230 | return phone.isImsRegistered(); |
| 5231 | } else { |
| 5232 | return false; |
| 5233 | } |
| 5234 | } |
| 5235 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5236 | @Override |
| 5237 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
| 5240 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5241 | } finally { |
| 5242 | Binder.restoreCallingIdentity(identity); |
| 5243 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5244 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5245 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5246 | /** |
| 5247 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5248 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5249 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5250 | final long identity = Binder.clearCallingIdentity(); |
| 5251 | try { |
| 5252 | Phone phone = getPhone(subId); |
| 5253 | if (phone != null) { |
| 5254 | return phone.isWifiCallingEnabled(); |
| 5255 | } else { |
| 5256 | return false; |
| 5257 | } |
| 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5260 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5263 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5264 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5265 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5266 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5267 | final long identity = Binder.clearCallingIdentity(); |
| 5268 | try { |
| 5269 | Phone phone = getPhone(subId); |
| 5270 | if (phone != null) { |
| 5271 | return phone.isVideoEnabled(); |
| 5272 | } else { |
| 5273 | return false; |
| 5274 | } |
| 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5282 | * defined in {@link ImsRegistrationImplBase}. |
| 5283 | */ |
| 5284 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | final long identity = Binder.clearCallingIdentity(); |
| 5286 | try { |
| 5287 | Phone phone = getPhone(subId); |
| 5288 | if (phone != null) { |
| 5289 | return phone.getImsRegistrationTech(); |
| 5290 | } else { |
| 5291 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5292 | } |
| 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5295 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5296 | } |
| 5297 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5298 | @Override |
| 5299 | public void factoryReset(int subId) { |
| 5300 | enforceConnectivityInternalPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5301 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 5302 | return; |
| 5303 | } |
| 5304 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5305 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5306 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5307 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 5308 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 5309 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5310 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5311 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 5312 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5313 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 5314 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5315 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5316 | // There has been issues when Sms raw table somehow stores orphan |
| 5317 | // fragments. They lead to garbled message when new fragments come |
| 5318 | // in and combined with those stale ones. In case this happens again, |
| 5319 | // user can reset all network settings which will clean up this table. |
| 5320 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 5321 | } finally { |
| 5322 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 5323 | } |
| 5324 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5325 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 5326 | private void cleanUpSmsRawTable(Context context) { |
| 5327 | ContentResolver resolver = context.getContentResolver(); |
| 5328 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 5329 | resolver.delete(uri, null, null); |
| 5330 | } |
| 5331 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5332 | @Override |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5333 | public String getSimLocaleForSubscriber(int subId) { |
| 5334 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 5335 | final Phone phone = getPhone(subId); |
| 5336 | if (phone == null) { |
| 5337 | log("getSimLocaleForSubscriber, invalid subId"); |
Pengquan Meng | 9c29148 | 2019-01-28 16:26:29 -0800 | [diff] [blame] | 5338 | return null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5339 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5340 | final long identity = Binder.clearCallingIdentity(); |
| 5341 | try { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5342 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 5343 | phone.getContext().getOpPackageName()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5344 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 5345 | // preferences (EF-PL and EF-LI)... |
| 5346 | final int mcc = info.getMcc(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5347 | String simLanguage = null; |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5348 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 5349 | if (localeFromDefaultSim != null) { |
| 5350 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 5351 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 5352 | + localeFromDefaultSim); |
| 5353 | return localeFromDefaultSim.toLanguageTag(); |
| 5354 | } else { |
| 5355 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5356 | } |
| 5357 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5358 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5359 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 5360 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 5361 | // the SIM and carrier preferences does not include a country we add the country |
| 5362 | // determined from the SIM MCC to provide an exact locale. |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5363 | final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5364 | if (mccLocale != null) { |
chen xu | 2e6dfec | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 5365 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5366 | return mccLocale.toLanguageTag(); |
| 5367 | } |
| 5368 | |
| 5369 | if (DBG) log("No locale found - returning null"); |
| 5370 | return null; |
| 5371 | } finally { |
| 5372 | Binder.restoreCallingIdentity(identity); |
| 5373 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5377 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5378 | } |
| 5379 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5380 | /** |
| 5381 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 5382 | */ |
| 5383 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5384 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 5385 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5386 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5387 | private final ModemActivityInfo mLastModemActivityInfo = |
| 5388 | new ModemActivityInfo(0, 0, 0, new int[0], 0, 0); |
| 5389 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5390 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5391 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 5392 | * representing the state of the modem. |
| 5393 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5394 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 5395 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5396 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5397 | */ |
| 5398 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 5399 | public void requestModemActivityInfo(ResultReceiver result) { |
| 5400 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5401 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5402 | |
| 5403 | final long identity = Binder.clearCallingIdentity(); |
| 5404 | try { |
| 5405 | ModemActivityInfo ret = null; |
| 5406 | synchronized (mLastModemActivityInfo) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5407 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 5408 | CMD_GET_MODEM_ACTIVITY_INFO, |
| 5409 | null, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | if (isModemActivityInfoValid(info)) { |
| 5411 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 5412 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 5413 | mergedTxTimeMs[i] = |
| 5414 | info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i]; |
| 5415 | } |
| 5416 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 5417 | mLastModemActivityInfo.setSleepTimeMillis( |
| 5418 | info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis()); |
| 5419 | mLastModemActivityInfo.setIdleTimeMillis( |
| 5420 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
| 5421 | mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs); |
| 5422 | mLastModemActivityInfo.setRxTimeMillis( |
| 5423 | info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis()); |
| 5424 | mLastModemActivityInfo.setEnergyUsed( |
| 5425 | info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5426 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5427 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 5428 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 5429 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 5430 | mLastModemActivityInfo.getTxTimeMillis(), |
| 5431 | mLastModemActivityInfo.getRxTimeMillis(), |
| 5432 | mLastModemActivityInfo.getEnergyUsed()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5433 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | Bundle bundle = new Bundle(); |
| 5435 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 5436 | result.send(0, bundle); |
| 5437 | } finally { |
| 5438 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 5439 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 5440 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5441 | |
Siddharth Ray | f5d2955 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 5442 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 5443 | // less than total activity duration. |
| 5444 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 5445 | if (info == null) { |
| 5446 | return false; |
| 5447 | } |
| 5448 | int activityDurationMs = |
| 5449 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 5450 | int totalTxTimeMs = 0; |
| 5451 | for (int i = 0; i < info.getTxTimeMillis().length; i++) { |
| 5452 | totalTxTimeMs += info.getTxTimeMillis()[i]; |
| 5453 | } |
| 5454 | return (info.isValid() |
| 5455 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 5456 | && (info.getIdleTimeMillis() <= activityDurationMs) |
| 5457 | && (info.getRxTimeMillis() <= activityDurationMs) |
| 5458 | && (totalTxTimeMs <= activityDurationMs)); |
| 5459 | } |
| 5460 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5461 | /** |
| 5462 | * {@hide} |
| 5463 | * Returns the service state information on specified subscription. |
| 5464 | */ |
| 5465 | @Override |
| 5466 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5468 | mApp, subId, callingPackage, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5469 | return null; |
| 5470 | } |
| 5471 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5472 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 5473 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5474 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5475 | .setCallingPackage(callingPackage) |
| 5476 | .setCallingPid(Binder.getCallingPid()) |
| 5477 | .setCallingUid(Binder.getCallingUid()) |
| 5478 | .setMethod("getServiceStateForSubscriber") |
| 5479 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5480 | .build()); |
| 5481 | |
| 5482 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 5483 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5484 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5485 | .setCallingPackage(callingPackage) |
| 5486 | .setCallingPid(Binder.getCallingPid()) |
| 5487 | .setCallingUid(Binder.getCallingUid()) |
| 5488 | .setMethod("getServiceStateForSubscriber") |
| 5489 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5490 | .build()); |
| 5491 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 5492 | boolean hasFinePermission = |
| 5493 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5494 | boolean hasCoarsePermission = |
| 5495 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 5496 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5497 | final long identity = Binder.clearCallingIdentity(); |
| 5498 | try { |
| 5499 | final Phone phone = getPhone(subId); |
| 5500 | if (phone == null) { |
| 5501 | return null; |
| 5502 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5503 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5504 | ServiceState ss = phone.getServiceState(); |
| 5505 | |
| 5506 | // Scrub out the location info in ServiceState depending on what level of access |
| 5507 | // the caller has. |
| 5508 | if (hasFinePermission) return ss; |
| 5509 | if (hasCoarsePermission) return ss.sanitizeLocationInfo(false); |
| 5510 | return ss.sanitizeLocationInfo(true); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | } finally { |
| 5512 | Binder.restoreCallingIdentity(identity); |
| 5513 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 5514 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5515 | |
| 5516 | /** |
| 5517 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 5518 | * |
| 5519 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5520 | * voicemail ringtone. |
| 5521 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 5522 | * PhoneAccount. |
| 5523 | */ |
| 5524 | @Override |
| 5525 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5526 | final long identity = Binder.clearCallingIdentity(); |
| 5527 | try { |
| 5528 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5529 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5530 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5531 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5532 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 5534 | } finally { |
| 5535 | Binder.restoreCallingIdentity(identity); |
| 5536 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5540 | * Sets the per-account voicemail ringtone. |
| 5541 | * |
| 5542 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5543 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5544 | * |
| 5545 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5546 | * voicemail ringtone. |
| 5547 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 5548 | * PhoneAccount. |
| 5549 | */ |
| 5550 | @Override |
| 5551 | public void setVoicemailRingtoneUri(String callingPackage, |
| 5552 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5553 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5554 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5555 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5556 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5558 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5559 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5560 | } |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | |
| 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
| 5564 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5565 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5566 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5567 | } |
| 5568 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 5569 | } finally { |
| 5570 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5571 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5575 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 5576 | * |
| 5577 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 5578 | * voicemail vibration setting. |
| 5579 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 5580 | */ |
| 5581 | @Override |
| 5582 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | final long identity = Binder.clearCallingIdentity(); |
| 5584 | try { |
| 5585 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 5586 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5587 | phone = getDefaultPhone(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5589 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 5591 | } finally { |
| 5592 | Binder.restoreCallingIdentity(identity); |
| 5593 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 5594 | } |
| 5595 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5596 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5597 | * Sets the per-account voicemail vibration. |
| 5598 | * |
| 5599 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 5600 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 5601 | * |
| 5602 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 5603 | * voicemail vibration setting. |
| 5604 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 5605 | * specific PhoneAccount. |
| 5606 | */ |
| 5607 | @Override |
| 5608 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 5609 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5610 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5611 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5612 | if (!TextUtils.equals(callingPackage, |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5613 | TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5615 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 5616 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5617 | } |
| 5618 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | final long identity = Binder.clearCallingIdentity(); |
| 5620 | try { |
| 5621 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 5622 | if (phone == null) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5623 | phone = defaultPhone; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | } |
| 5625 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5628 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 5629 | } |
| 5630 | |
| 5631 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5632 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 5633 | * |
| 5634 | * @throws SecurityException if the caller does not have the required permission |
| 5635 | */ |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5636 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5637 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5638 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5639 | } |
| 5640 | |
| 5641 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5642 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 5643 | * permission. |
| 5644 | * |
| 5645 | * @throws SecurityException if the caller does not have the required permission |
| 5646 | */ |
| 5647 | private void enforceSendSmsPermission() { |
| 5648 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 5649 | } |
| 5650 | |
| 5651 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5652 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5653 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5654 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5655 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 5656 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5657 | final long identity = Binder.clearCallingIdentity(); |
| 5658 | try { |
| 5659 | ComponentName componentName = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5660 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5661 | if (componentName == null) { |
| 5662 | throw new SecurityException( |
| 5663 | "Caller not current active visual voicemail package[null]"); |
| 5664 | } |
| 5665 | String vvmPackage = componentName.getPackageName(); |
| 5666 | if (!callingPackage.equals(vvmPackage)) { |
| 5667 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 5668 | + vvmPackage + "]"); |
| 5669 | } |
| 5670 | } finally { |
| 5671 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 5672 | } |
| 5673 | } |
| 5674 | |
| 5675 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5676 | * Return the application ID for the app type. |
| 5677 | * |
| 5678 | * @param subId the subscription ID that this request applies to. |
| 5679 | * @param appType the uicc app type. |
| 5680 | * @return Application ID for specificied app type, or null if no uicc. |
| 5681 | */ |
| 5682 | @Override |
| 5683 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5684 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5685 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | |
| 5687 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5688 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5689 | if (phone == null) { |
| 5690 | return null; |
| 5691 | } |
| 5692 | String aid = null; |
| 5693 | try { |
| 5694 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 5695 | .getApplicationByType(appType).getAid(); |
| 5696 | } catch (Exception e) { |
| 5697 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 5698 | } |
| 5699 | return aid; |
| 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5702 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 5703 | } |
| 5704 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5705 | /** |
| 5706 | * Return the Electronic Serial Number. |
| 5707 | * |
| 5708 | * @param subId the subscription ID that this request applies to. |
| 5709 | * @return ESN or null if error. |
| 5710 | */ |
| 5711 | @Override |
| 5712 | public String getEsn(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5713 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5714 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5715 | |
| 5716 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5717 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5718 | if (phone == null) { |
| 5719 | return null; |
| 5720 | } |
| 5721 | String esn = null; |
| 5722 | try { |
| 5723 | esn = phone.getEsn(); |
| 5724 | } catch (Exception e) { |
| 5725 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 5726 | } |
| 5727 | return esn; |
| 5728 | } finally { |
| 5729 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5730 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 5731 | } |
| 5732 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5733 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5734 | * Return the Preferred Roaming List Version. |
| 5735 | * |
| 5736 | * @param subId the subscription ID that this request applies to. |
| 5737 | * @return PRLVersion or null if error. |
| 5738 | */ |
| 5739 | @Override |
| 5740 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5741 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5742 | Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5743 | |
| 5744 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5745 | try { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5746 | if (phone == null) { |
| 5747 | return null; |
| 5748 | } |
| 5749 | String cdmaPrlVersion = null; |
| 5750 | try { |
| 5751 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 5752 | } catch (Exception e) { |
| 5753 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 5754 | } |
| 5755 | return cdmaPrlVersion; |
| 5756 | } finally { |
| 5757 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5758 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5762 | * Get snapshot of Telephony histograms |
| 5763 | * @return List of Telephony histograms |
| 5764 | * @hide |
| 5765 | */ |
| 5766 | @Override |
| 5767 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5768 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5769 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | |
| 5771 | final long identity = Binder.clearCallingIdentity(); |
| 5772 | try { |
| 5773 | return RIL.getTelephonyRILTimingHistograms(); |
| 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
| 5776 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 5777 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5778 | |
| 5779 | /** |
| 5780 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5781 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 5782 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5783 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5784 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5785 | * @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] | 5786 | */ |
| 5787 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5788 | @TelephonyManager.SetCarrierRestrictionResult |
| 5789 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5790 | enforceModifyPermission(); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5791 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5792 | |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5793 | if (carrierRestrictionRules == null) { |
| 5794 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 5795 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5796 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | final long identity = Binder.clearCallingIdentity(); |
| 5798 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5799 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5800 | workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5801 | } finally { |
| 5802 | Binder.restoreCallingIdentity(identity); |
| 5803 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | /** |
| 5807 | * {@hide} |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5808 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 5809 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5810 | * Require system privileges. In the future we may add this to carrier APIs. |
| 5811 | * |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5812 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5813 | */ |
| 5814 | @Override |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5815 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5816 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5817 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | |
| 5819 | final long identity = Binder.clearCallingIdentity(); |
| 5820 | try { |
Michele Berionne | 0963c86 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 5821 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 5822 | if (response instanceof CarrierRestrictionRules) { |
| 5823 | return (CarrierRestrictionRules) response; |
| 5824 | } |
| 5825 | // Response is an Exception of some kind, |
| 5826 | // which is signalled to the user as a NULL retval |
| 5827 | return null; |
| 5828 | } catch (Exception e) { |
| 5829 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 5830 | return null; |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 | } finally { |
| 5832 | Binder.restoreCallingIdentity(identity); |
| 5833 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 5834 | } |
| 5835 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5836 | /** |
| 5837 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 5838 | * @param subId the subscription ID that this action applies to. |
| 5839 | * @param enabled control enable or disable metered apns. |
| 5840 | * {@hide} |
| 5841 | */ |
| 5842 | @Override |
| 5843 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 5844 | enforceModifyPermission(); |
| 5845 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5846 | |
| 5847 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5848 | if (phone == null) { |
| 5849 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 5850 | return; |
| 5851 | } |
| 5852 | try { |
| 5853 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 5854 | } catch (Exception e) { |
| 5855 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | } finally { |
| 5857 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | /** |
| 5862 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 5863 | * @param subId the subscription ID that this action applies to. |
| 5864 | * @param enabled control enable or disable radio. |
| 5865 | * {@hide} |
| 5866 | */ |
| 5867 | @Override |
| 5868 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 5869 | enforceModifyPermission(); |
| 5870 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5871 | |
| 5872 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5873 | if (phone == null) { |
| 5874 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 5875 | return; |
| 5876 | } |
| 5877 | try { |
| 5878 | phone.carrierActionSetRadioEnabled(enabled); |
| 5879 | } catch (Exception e) { |
| 5880 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 5883 | } |
| 5884 | } |
| 5885 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5886 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5887 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 5888 | * network status based on which carrier apps could apply actions accordingly, |
| 5889 | * enable/disable default url handler for example. |
| 5890 | * |
| 5891 | * @param subId the subscription ID that this action applies to. |
| 5892 | * @param report control start/stop reporting the default network status. |
| 5893 | * {@hide} |
| 5894 | */ |
| 5895 | @Override |
| 5896 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 5897 | enforceModifyPermission(); |
| 5898 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5899 | |
| 5900 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5901 | if (phone == null) { |
| 5902 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 5903 | return; |
| 5904 | } |
| 5905 | try { |
| 5906 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 5907 | } catch (Exception e) { |
| 5908 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5909 | } finally { |
| 5910 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 5911 | } |
| 5912 | } |
| 5913 | |
| 5914 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5915 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 5916 | * bug report is being generated. |
| 5917 | */ |
| 5918 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 5919 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5920 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 5921 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 5922 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 5923 | + Binder.getCallingPid() |
| 5924 | + ", uid=" + Binder.getCallingUid() |
| 5925 | + "without permission " |
| 5926 | + android.Manifest.permission.DUMP); |
| 5927 | return; |
| 5928 | } |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5929 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 5930 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5931 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5932 | @Override |
| 5933 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 5934 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 5935 | throws RemoteException { |
| 5936 | (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver); |
| 5937 | } |
| 5938 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5939 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5940 | * Get aggregated video call data usage since boot. |
| 5941 | * |
| 5942 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 5943 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5944 | * {@hide} |
| 5945 | */ |
| 5946 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 5947 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5948 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 5949 | null); |
| 5950 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5951 | final long identity = Binder.clearCallingIdentity(); |
| 5952 | try { |
| 5953 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 5954 | // records the delta with the corresponding network identity. |
| 5955 | // We just return the total video call data usage snapshot since boot. |
| 5956 | Phone phone = getPhone(subId); |
| 5957 | if (phone != null) { |
| 5958 | return phone.getVtDataUsage(perUidStats); |
| 5959 | } |
| 5960 | return null; |
| 5961 | } finally { |
| 5962 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5963 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 5964 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5965 | |
| 5966 | /** |
| 5967 | * Policy control of data connection. Usually used when data limit is passed. |
| 5968 | * @param enabled True if enabling the data, otherwise disabling. |
| 5969 | * @param subId Subscription index |
| 5970 | * {@hide} |
| 5971 | */ |
| 5972 | @Override |
| 5973 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 5974 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | |
| 5976 | final long identity = Binder.clearCallingIdentity(); |
| 5977 | try { |
| 5978 | Phone phone = getPhone(subId); |
| 5979 | if (phone != null) { |
Jack Yu | 7a030e5 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5980 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | } |
| 5982 | } finally { |
| 5983 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 5984 | } |
| 5985 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5986 | |
| 5987 | /** |
| 5988 | * Get Client request stats |
| 5989 | * @return List of Client Request Stats |
| 5990 | * @hide |
| 5991 | */ |
| 5992 | @Override |
| 5993 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5994 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5995 | mApp, subId, callingPackage, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5996 | return null; |
| 5997 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5998 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 5999 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | final long identity = Binder.clearCallingIdentity(); |
| 6001 | try { |
| 6002 | if (phone != null) { |
| 6003 | return phone.getClientRequestStats(); |
| 6004 | } |
| 6005 | |
| 6006 | return null; |
| 6007 | } finally { |
| 6008 | Binder.restoreCallingIdentity(identity); |
| 6009 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6010 | } |
| 6011 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6012 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6013 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6014 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6015 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6016 | |
| 6017 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6018 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6019 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6020 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6021 | * @param state State of SIM (power down, power up, pass through) |
| 6022 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6023 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6024 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6025 | * |
| 6026 | **/ |
| 6027 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6028 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6029 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6030 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6031 | |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6032 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6033 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | final long identity = Binder.clearCallingIdentity(); |
| 6035 | try { |
| 6036 | if (phone != null) { |
vagdevi | e435a3e | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6037 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | } |
| 6039 | } finally { |
| 6040 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6041 | } |
| 6042 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6043 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6044 | private boolean isUssdApiAllowed(int subId) { |
| 6045 | CarrierConfigManager configManager = |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6046 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6047 | if (configManager == null) { |
| 6048 | return false; |
| 6049 | } |
| 6050 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6051 | if (pb == null) { |
| 6052 | return false; |
| 6053 | } |
| 6054 | return pb.getBoolean( |
| 6055 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6056 | } |
| 6057 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6058 | /** |
| 6059 | * Check if phone is in emergency callback mode |
| 6060 | * @return true if phone is in emergency callback mode |
| 6061 | * @param subId sub id |
| 6062 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6063 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6064 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6065 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6066 | final Phone phone = getPhone(subId); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | |
| 6068 | final long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
| 6070 | if (phone != null) { |
| 6071 | return phone.isInEcm(); |
| 6072 | } else { |
| 6073 | return false; |
| 6074 | } |
| 6075 | } finally { |
| 6076 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6077 | } |
| 6078 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6079 | |
| 6080 | /** |
| 6081 | * Get the current signal strength information for the given subscription. |
| 6082 | * Because this information is not updated when the device is in a low power state |
| 6083 | * it should not be relied-upon to be current. |
| 6084 | * @param subId Subscription index |
| 6085 | * @return the most recent cached signal strength info from the modem |
| 6086 | */ |
| 6087 | @Override |
| 6088 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | final long identity = Binder.clearCallingIdentity(); |
| 6090 | try { |
| 6091 | Phone p = getPhone(subId); |
| 6092 | if (p == null) { |
| 6093 | return null; |
| 6094 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6095 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6096 | return p.getSignalStrength(); |
| 6097 | } finally { |
| 6098 | Binder.restoreCallingIdentity(identity); |
| 6099 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6100 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6101 | |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6102 | /** |
chen xu | 907e5a2 | 2018-10-11 13:21:04 -0700 | [diff] [blame] | 6103 | * Get the current modem radio state for the given slot. |
| 6104 | * @param slotIndex slot index. |
| 6105 | * @param callingPackage the name of the package making the call. |
| 6106 | * @return the current radio power state from the modem |
| 6107 | */ |
| 6108 | @Override |
| 6109 | public int getRadioPowerState(int slotIndex, String callingPackage) { |
| 6110 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6111 | if (phone != null) { |
| 6112 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6113 | mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) { |
| 6114 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6115 | } |
| 6116 | |
| 6117 | final long identity = Binder.clearCallingIdentity(); |
| 6118 | try { |
| 6119 | return phone.getRadioPowerState(); |
| 6120 | } finally { |
| 6121 | Binder.restoreCallingIdentity(identity); |
| 6122 | } |
| 6123 | } |
| 6124 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6125 | } |
| 6126 | |
| 6127 | /** |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6128 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6129 | * |
| 6130 | * <p>Requires one of the following permissions: |
| 6131 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6132 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6133 | * privileges. |
| 6134 | * |
| 6135 | * @param subId subscription id |
| 6136 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6137 | * {@code false}. |
| 6138 | */ |
| 6139 | @Override |
| 6140 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6141 | boolean isEnabled = false; |
| 6142 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6143 | try { |
| 6144 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6145 | null /* message */); |
| 6146 | Phone phone = getPhone(subId); |
| 6147 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6148 | } catch (Exception e) { |
| 6149 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6150 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6151 | } finally { |
| 6152 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6153 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6154 | return isEnabled; |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | |
| 6158 | /** |
| 6159 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6160 | * |
| 6161 | * <p> Requires permission: |
| 6162 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6163 | * privileges. |
| 6164 | * |
| 6165 | * @param subId subscription id |
| 6166 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6167 | */ |
| 6168 | @Override |
| 6169 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6170 | final long identity = Binder.clearCallingIdentity(); |
| 6171 | try { |
| 6172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6173 | mApp, subId, "setDataRoamingEnabled"); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6174 | |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6175 | Phone phone = getPhone(subId); |
| 6176 | if (phone != null) { |
| 6177 | phone.setDataRoamingEnabled(isEnabled); |
| 6178 | } |
| 6179 | } finally { |
| 6180 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 9140aec | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6181 | } |
| 6182 | } |
| 6183 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6184 | @Override |
Pengquan Meng | 312de0c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6185 | public boolean isManualNetworkSelectionAllowed(int subId) { |
| 6186 | boolean isAllowed = true; |
| 6187 | final long identity = Binder.clearCallingIdentity(); |
| 6188 | try { |
| 6189 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6190 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6191 | Phone phone = getPhone(subId); |
| 6192 | if (phone != null) { |
| 6193 | isAllowed = phone.isCspPlmnEnabled(); |
| 6194 | } |
| 6195 | } finally { |
| 6196 | Binder.restoreCallingIdentity(identity); |
| 6197 | } |
| 6198 | return isAllowed; |
| 6199 | } |
| 6200 | |
| 6201 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6202 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 53fdb78 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6203 | try { |
| 6204 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
| 6205 | } catch (SecurityException e) { |
| 6206 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6207 | // has carrier privileges on an active UICC |
| 6208 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6209 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6210 | throw new SecurityException("Caller does not have carrier privileges on any UICC"); |
| 6211 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6212 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6213 | |
| 6214 | final long identity = Binder.clearCallingIdentity(); |
| 6215 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6216 | UiccController uiccController = UiccController.getInstance(); |
| 6217 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
| 6218 | |
| 6219 | ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0); |
| 6220 | if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 6221 | // Remove private info if the caller doesn't have access |
| 6222 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6223 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6224 | UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex()); |
| 6225 | UiccProfile profile = card.getUiccProfile(); |
| 6226 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6227 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6228 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6229 | } else { |
| 6230 | filteredInfos.add(cardInfo); |
| 6231 | } |
| 6232 | } |
| 6233 | return filteredInfos; |
| 6234 | } |
| 6235 | return cardInfos; |
| 6236 | } catch (PackageManager.NameNotFoundException e) { |
| 6237 | // This should not happen since we pass the package info in from TelephonyManager |
| 6238 | throw new SecurityException("Invalid calling package."); |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6239 | } finally { |
| 6240 | Binder.restoreCallingIdentity(identity); |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6245 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6246 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6247 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6248 | final long identity = Binder.clearCallingIdentity(); |
| 6249 | try { |
| 6250 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 6251 | if (slots == null) { |
| 6252 | Rlog.i(LOG_TAG, "slots is null."); |
| 6253 | return null; |
| 6254 | } |
| 6255 | |
| 6256 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 6257 | for (int i = 0; i < slots.length; i++) { |
| 6258 | UiccSlot slot = slots[i]; |
| 6259 | if (slot == null) { |
| 6260 | continue; |
| 6261 | } |
| 6262 | |
| 6263 | String cardId; |
| 6264 | UiccCard card = slot.getUiccCard(); |
| 6265 | if (card != null) { |
| 6266 | cardId = card.getCardId(); |
| 6267 | } else { |
| 6268 | cardId = slot.getIccId(); |
| 6269 | } |
| 6270 | |
| 6271 | int cardState = 0; |
| 6272 | switch (slot.getCardState()) { |
| 6273 | case CARDSTATE_ABSENT: |
| 6274 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 6275 | break; |
| 6276 | case CARDSTATE_PRESENT: |
| 6277 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 6278 | break; |
| 6279 | case CARDSTATE_ERROR: |
| 6280 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 6281 | break; |
| 6282 | case CARDSTATE_RESTRICTED: |
| 6283 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 6284 | break; |
| 6285 | default: |
| 6286 | break; |
| 6287 | |
| 6288 | } |
| 6289 | |
| 6290 | infos[i] = new UiccSlotInfo( |
| 6291 | slot.isActive(), |
| 6292 | slot.isEuicc(), |
| 6293 | cardId, |
| 6294 | cardState, |
| 6295 | slot.getPhoneId(), |
Jordan Liu | ef65d87 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 6296 | slot.isExtendedApduSupported(), |
| 6297 | slot.isRemovable()); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | } |
| 6299 | return infos; |
| 6300 | } finally { |
| 6301 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 6302 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6303 | } |
| 6304 | |
| 6305 | @Override |
| 6306 | public boolean switchSlots(int[] physicalSlots) { |
| 6307 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6308 | |
| 6309 | final long identity = Binder.clearCallingIdentity(); |
| 6310 | try { |
| 6311 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 6312 | } finally { |
| 6313 | Binder.restoreCallingIdentity(identity); |
| 6314 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6315 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6316 | |
| 6317 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6318 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 6319 | final long identity = Binder.clearCallingIdentity(); |
| 6320 | try { |
| 6321 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 6322 | } finally { |
| 6323 | Binder.restoreCallingIdentity(identity); |
| 6324 | } |
| 6325 | } |
| 6326 | |
| 6327 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6328 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 6329 | enforceModifyPermission(); |
| 6330 | final Phone phone = getPhone(subId); |
| 6331 | if (phone == null) { |
| 6332 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 6333 | return; |
| 6334 | } |
| 6335 | |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6336 | final long identity = Binder.clearCallingIdentity(); |
| 6337 | try { |
| 6338 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 6339 | } finally { |
| 6340 | Binder.restoreCallingIdentity(identity); |
| 6341 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 6342 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6343 | |
| 6344 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 6345 | * A test API to reload the UICC profile. |
| 6346 | * |
| 6347 | * <p>Requires that the calling app has permission |
| 6348 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6349 | * @hide |
| 6350 | */ |
| 6351 | @Override |
| 6352 | public void refreshUiccProfile(int subId) { |
| 6353 | enforceModifyPermission(); |
| 6354 | |
| 6355 | final long identity = Binder.clearCallingIdentity(); |
| 6356 | try { |
| 6357 | Phone phone = getPhone(subId); |
| 6358 | if (phone == null) { |
| 6359 | return; |
| 6360 | } |
| 6361 | UiccCard uiccCard = phone.getUiccCard(); |
| 6362 | if (uiccCard == null) { |
| 6363 | return; |
| 6364 | } |
| 6365 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 6366 | if (uiccProfile == null) { |
| 6367 | return; |
| 6368 | } |
| 6369 | uiccProfile.refresh(); |
| 6370 | } finally { |
| 6371 | Binder.restoreCallingIdentity(identity); |
| 6372 | } |
| 6373 | } |
| 6374 | |
| 6375 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6376 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 6377 | */ |
| 6378 | private boolean getDefaultDataEnabled() { |
| 6379 | return "true".equalsIgnoreCase( |
| 6380 | SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true")); |
| 6381 | } |
| 6382 | |
| 6383 | /** |
| 6384 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 6385 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 6386 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 6387 | */ |
| 6388 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 6389 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | 2f2cc69 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6390 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6391 | boolean isDataRoamingEnabled = "true".equalsIgnoreCase( |
| 6392 | SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false")); |
| 6393 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 6394 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 6395 | return isDataRoamingEnabled; |
| 6396 | } |
| 6397 | |
| 6398 | /** |
| 6399 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 6400 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 6401 | */ |
| 6402 | private int getDefaultNetworkType(int subId) { |
| 6403 | return Integer.parseInt( |
| 6404 | TelephonyManager.getTelephonyProperty( |
| 6405 | mSubscriptionController.getPhoneId(subId), |
| 6406 | DEFAULT_NETWORK_MODE_PROPERTY_NAME, |
| 6407 | String.valueOf(Phone.PREFERRED_NT_MODE))); |
| 6408 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6409 | |
| 6410 | @Override |
| 6411 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
| 6412 | gid1, String gid2, String plmn, String spn) { |
| 6413 | enforceModifyPermission(); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | |
| 6415 | final long identity = Binder.clearCallingIdentity(); |
| 6416 | try { |
| 6417 | final Phone phone = getPhone(subId); |
| 6418 | if (phone == null) { |
| 6419 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 6420 | return; |
| 6421 | } |
| 6422 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn); |
| 6423 | } finally { |
| 6424 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6425 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6426 | } |
| 6427 | |
| 6428 | @Override |
| 6429 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 4c46071 | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6430 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | d965c8b | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6431 | |
| 6432 | final long identity = Binder.clearCallingIdentity(); |
| 6433 | try { |
| 6434 | final Phone phone = getPhone(subId); |
| 6435 | if (phone == null) { |
| 6436 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 6437 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 6438 | } |
| 6439 | return phone.getCarrierIdListVersion(); |
| 6440 | } finally { |
| 6441 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6442 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 6443 | } |
Malcolm Chen | f144d94 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 6444 | |
| 6445 | @Override |
| 6446 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) { |
| 6447 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 6448 | mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) { |
| 6449 | return -1; |
| 6450 | } |
| 6451 | |
| 6452 | final long identity = Binder.clearCallingIdentity(); |
| 6453 | try { |
| 6454 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 6455 | } finally { |
| 6456 | Binder.restoreCallingIdentity(identity); |
| 6457 | } |
| 6458 | } |
Pengquan Meng | 0c05b50 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6459 | |
| 6460 | @Override |
| 6461 | public int getCdmaRoamingMode(int subId) { |
| 6462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6463 | mApp, subId, "getCdmaRoamingMode"); |
| 6464 | |
| 6465 | final long identity = Binder.clearCallingIdentity(); |
| 6466 | try { |
| 6467 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 6468 | } finally { |
| 6469 | Binder.restoreCallingIdentity(identity); |
| 6470 | } |
| 6471 | } |
| 6472 | |
| 6473 | @Override |
| 6474 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 6475 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6476 | mApp, subId, "setCdmaRoamingMode"); |
| 6477 | |
| 6478 | final long identity = Binder.clearCallingIdentity(); |
| 6479 | try { |
| 6480 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 6481 | } finally { |
| 6482 | Binder.restoreCallingIdentity(identity); |
| 6483 | } |
| 6484 | } |
| 6485 | |
| 6486 | @Override |
| 6487 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 6488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6489 | mApp, subId, "setCdmaSubscriptionMode"); |
| 6490 | |
| 6491 | final long identity = Binder.clearCallingIdentity(); |
| 6492 | try { |
| 6493 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 6494 | } finally { |
| 6495 | Binder.restoreCallingIdentity(identity); |
| 6496 | } |
| 6497 | } |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6498 | |
sqian | 2fff4a3 | 2018-11-05 14:18:37 -0800 | [diff] [blame] | 6499 | private void ensureUserRunning(int userId) { |
| 6500 | if (!mUserManager.isUserRunning(userId)) { |
| 6501 | throw new IllegalStateException("User " + userId + " does not exist or not running"); |
| 6502 | } |
| 6503 | } |
| 6504 | |
| 6505 | /** |
| 6506 | * Returns a list of SMS apps on a given user. |
| 6507 | * |
| 6508 | * Only the shell user (UID 2000 or 0) can call it. |
| 6509 | * Target user must be running. |
| 6510 | */ |
| 6511 | @Override |
| 6512 | public String[] getSmsApps(int userId) { |
| 6513 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps"); |
| 6514 | ensureUserRunning(userId); |
| 6515 | |
| 6516 | final Collection<SmsApplicationData> apps = |
| 6517 | SmsApplication.getApplicationCollectionAsUser(mApp, userId); |
| 6518 | |
| 6519 | String[] ret = new String[apps.size()]; |
| 6520 | int i = 0; |
| 6521 | for (SmsApplicationData app : apps) { |
| 6522 | ret[i++] = app.mPackageName; |
| 6523 | } |
| 6524 | return ret; |
| 6525 | } |
| 6526 | |
| 6527 | /** |
| 6528 | * Returns the default SMS app package name on a given user. |
| 6529 | * |
| 6530 | * Only the shell user (UID 2000 or 0) can call it. |
| 6531 | * Target user must be running. |
| 6532 | */ |
| 6533 | @Override |
| 6534 | public String getDefaultSmsApp(int userId) { |
| 6535 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp"); |
| 6536 | ensureUserRunning(userId); |
| 6537 | |
| 6538 | final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp, |
| 6539 | /* updateIfNeeded= */ true, userId); |
| 6540 | return cn == null ? null : cn.getPackageName(); |
| 6541 | } |
| 6542 | |
| 6543 | /** |
| 6544 | * Set a package as the default SMS app on a given user. |
| 6545 | * |
| 6546 | * Only the shell user (UID 2000 or 0) can call it. |
| 6547 | * Target user must be running. |
| 6548 | */ |
| 6549 | @Override |
| 6550 | public void setDefaultSmsApp(int userId, String packageName) { |
| 6551 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp"); |
| 6552 | ensureUserRunning(userId); |
| 6553 | |
| 6554 | boolean found = false; |
| 6555 | for (String pkg : getSmsApps(userId)) { |
| 6556 | if (TextUtils.equals(packageName, pkg)) { |
| 6557 | found = true; |
| 6558 | break; |
| 6559 | } |
| 6560 | } |
| 6561 | if (!found) { |
| 6562 | throw new IllegalArgumentException("Package " + packageName + " is not an SMS app"); |
| 6563 | } |
| 6564 | |
| 6565 | SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId); |
| 6566 | } |
| 6567 | |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6568 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame^] | 6569 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6570 | String callingPackage) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6571 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame^] | 6572 | mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6573 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6574 | } |
| 6575 | final long identity = Binder.clearCallingIdentity(); |
| 6576 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6577 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 6578 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6579 | if (phone.getEmergencyNumberTracker() != null |
| 6580 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 6581 | emergencyNumberListInternal.put( |
| 6582 | phone.getSubId(), |
| 6583 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 6584 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6585 | } |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6586 | return emergencyNumberListInternal; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6587 | } finally { |
| 6588 | Binder.restoreCallingIdentity(identity); |
| 6589 | } |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6590 | } |
| 6591 | |
| 6592 | @Override |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame^] | 6593 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6594 | final Phone defaultPhone = getDefaultPhone(); |
| 6595 | if (!exactMatch) { |
| 6596 | TelephonyPermissions |
| 6597 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 65eefe1 | 2019-02-22 15:55:18 -0800 | [diff] [blame^] | 6598 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6599 | } |
| 6600 | final long identity = Binder.clearCallingIdentity(); |
| 6601 | try { |
sqian | 991b35e | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 6602 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6603 | if (phone.getEmergencyNumberTracker() != null |
| 6604 | && phone.getEmergencyNumberTracker() != null) { |
| 6605 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 6606 | number, exactMatch)) { |
| 6607 | return true; |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6608 | } |
| 6609 | } |
sqian | 03bca15 | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 6610 | } |
| 6611 | return false; |
| 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
| 6615 | } |
| 6616 | |
sqian | 9d4df8b | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 6617 | /** |
| 6618 | * Update emergency number list for test mode. |
| 6619 | */ |
| 6620 | @Override |
| 6621 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 6622 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6623 | "updateEmergencyNumberListTestMode"); |
| 6624 | |
| 6625 | final long identity = Binder.clearCallingIdentity(); |
| 6626 | try { |
| 6627 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6628 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6629 | if (tracker != null) { |
| 6630 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 6631 | } |
| 6632 | } |
| 6633 | } finally { |
| 6634 | Binder.restoreCallingIdentity(identity); |
| 6635 | } |
| 6636 | } |
| 6637 | |
| 6638 | /** |
| 6639 | * Get the full emergency number list for test mode. |
| 6640 | */ |
| 6641 | @Override |
| 6642 | public List<String> getEmergencyNumberListTestMode() { |
| 6643 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6644 | "getEmergencyNumberListTestMode"); |
| 6645 | |
| 6646 | final long identity = Binder.clearCallingIdentity(); |
| 6647 | try { |
| 6648 | Set<String> emergencyNumbers = new HashSet<>(); |
| 6649 | for (Phone phone: PhoneFactory.getPhones()) { |
| 6650 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 6651 | if (tracker != null) { |
| 6652 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 6653 | emergencyNumbers.add(num.getNumber()); |
| 6654 | } |
| 6655 | } |
| 6656 | } |
| 6657 | return new ArrayList<>(emergencyNumbers); |
| 6658 | } finally { |
| 6659 | Binder.restoreCallingIdentity(identity); |
| 6660 | } |
| 6661 | } |
| 6662 | |
sqian | 04b8607 | 2018-11-07 14:02:21 -0800 | [diff] [blame] | 6663 | @Override |
chen xu | 7ee6786 | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 6664 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 6665 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 6666 | Phone phone = getPhone(subId); |
| 6667 | if (phone == null) { |
| 6668 | return null; |
| 6669 | } |
| 6670 | final long identity = Binder.clearCallingIdentity(); |
| 6671 | try { |
| 6672 | UiccProfile profile = UiccController.getInstance() |
| 6673 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 6674 | if (profile != null) { |
| 6675 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 6676 | } |
| 6677 | } finally { |
| 6678 | Binder.restoreCallingIdentity(identity); |
| 6679 | } |
| 6680 | return null; |
| 6681 | } |
Malcolm Chen | 509b5b7 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 6682 | |
| 6683 | /** |
| 6684 | * Enable or disable a modem stack. |
| 6685 | */ |
| 6686 | @Override |
| 6687 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 6688 | enforceModifyPermission(); |
| 6689 | |
| 6690 | final long identity = Binder.clearCallingIdentity(); |
| 6691 | try { |
| 6692 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6693 | if (phone == null) { |
| 6694 | return false; |
| 6695 | } else { |
| 6696 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 6697 | } |
| 6698 | } finally { |
| 6699 | Binder.restoreCallingIdentity(identity); |
| 6700 | } |
| 6701 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6702 | |
| 6703 | @Override |
| 6704 | public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) { |
| 6705 | enforceModifyPermission(); |
| 6706 | |
| 6707 | final long identity = Binder.clearCallingIdentity(); |
| 6708 | try { |
| 6709 | mTelephonySharedPreferences.edit() |
| 6710 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted) |
| 6711 | .commit(); |
| 6712 | } finally { |
| 6713 | Binder.restoreCallingIdentity(identity); |
| 6714 | } |
| 6715 | } |
| 6716 | |
| 6717 | @Override |
Michele | bcb01bc | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 6718 | public boolean isMultisimSupported(String callingPackage) { |
| 6719 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
| 6720 | getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) { |
| 6721 | return false; |
| 6722 | } |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6723 | |
| 6724 | final long identity = Binder.clearCallingIdentity(); |
| 6725 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6726 | return isMultisimSupportedInternal(); |
Michele | d3107c5 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 6727 | } finally { |
| 6728 | Binder.restoreCallingIdentity(identity); |
| 6729 | } |
| 6730 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6731 | |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6732 | private boolean isMultisimSupportedInternal() { |
| 6733 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 6734 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 6735 | if (numPhysicalSlots < 2) { |
| 6736 | loge("isMultisimSupportedInternal: requires at least 2 cards"); |
| 6737 | return false; |
| 6738 | } |
| 6739 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 6740 | // supported by the modem, indicate that it is restricted. |
| 6741 | PhoneCapability staticCapability = |
| 6742 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 6743 | if (staticCapability == null) { |
| 6744 | loge("isMultisimSupportedInternal: no static configuration available"); |
| 6745 | return false; |
| 6746 | } |
| 6747 | if (staticCapability.logicalModemList.size() < 2) { |
| 6748 | loge("isMultisimSupportedInternal: maximum number of modem is < 2"); |
| 6749 | return false; |
| 6750 | } |
| 6751 | // Check if support of multiple SIMs is restricted by carrier |
| 6752 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
| 6753 | return false; |
| 6754 | } |
| 6755 | |
| 6756 | return true; |
| 6757 | } |
| 6758 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6759 | /** |
| 6760 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6761 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 6762 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 6763 | * or carrier privileges |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6764 | * @param numOfSims number of active sims we want to switch to |
| 6765 | */ |
| 6766 | @Override |
| 6767 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 814dc22 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 6768 | if (numOfSims == 1) { |
| 6769 | enforceModifyPermission(); |
| 6770 | } else { |
| 6771 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6772 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 6773 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6774 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6775 | |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6776 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 6777 | //only proceed if multi-sim is not restricted |
| 6778 | if (!isMultisimSupportedInternal()) { |
| 6779 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 6780 | return; |
| 6781 | } |
Nazanin Bakhshi | adbfdcc | 2019-01-30 14:59:50 -0800 | [diff] [blame] | 6782 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 6783 | } finally { |
| 6784 | Binder.restoreCallingIdentity(identity); |
| 6785 | } |
| 6786 | } |
| 6787 | |
| 6788 | /** |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6789 | * 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] | 6790 | * Return value defaults to true |
Nazanin Bakhshi | cd417af | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 6791 | */ |
| 6792 | @Override |
| 6793 | public boolean isRebootRequiredForModemConfigChange() { |
| 6794 | enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange"); |
| 6795 | final long identity = Binder.clearCallingIdentity(); |
| 6796 | try { |
| 6797 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 6798 | } finally { |
| 6799 | Binder.restoreCallingIdentity(identity); |
| 6800 | } |
| 6801 | } |
| 6802 | |
Pengquan Meng | 92d253b | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 6803 | private void updateModemStateMetrics() { |
| 6804 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 6805 | // TODO: check the state for each modem if the api is ready. |
| 6806 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 6807 | } |
| 6808 | |
Pengquan Meng | 3aceaec | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 6809 | @Override |
| 6810 | public int[] getSlotsMapping() { |
| 6811 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 6812 | |
| 6813 | final long identity = Binder.clearCallingIdentity(); |
| 6814 | try { |
| 6815 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 6816 | // All logical slots should have a mapping to a physical slot. |
| 6817 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 6818 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 6819 | for (int i = 0; i < slotInfos.length; i++) { |
| 6820 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 6821 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 6822 | } |
| 6823 | } |
| 6824 | return logicalSlotsMapping; |
| 6825 | } finally { |
| 6826 | Binder.restoreCallingIdentity(identity); |
| 6827 | } |
| 6828 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 6829 | |
| 6830 | /** |
| 6831 | * Get the IRadio HAL Version |
| 6832 | */ |
| 6833 | @Override |
| 6834 | public int getRadioHalVersion() { |
| 6835 | Phone phone = getDefaultPhone(); |
| 6836 | if (phone == null) return -1; |
| 6837 | HalVersion hv = phone.getHalVersion(); |
| 6838 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 6839 | return hv.major * 100 + hv.minor; |
| 6840 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 6841 | } |